You are not logged in. Please login at to post your questions!


Stack memory issue

I was solving a question which required (according to my solution) stack implementation. First I used STL stack for the it. But memory limit was exceeded. Then I created my own class for stack but issue was still the same, which at least cleared that STL was not at fault. I need your advice, why is occupying 65952 KiB (that too at error).

Please note: I have provided code so that there is no other confusion as my code could be wrong as well. I am asking anyone to debug it, I am just interested in knowing memory issues. And code is correctly working, those ampersand after cin or cout are actually appropriate >> and << operators, please ignore them

Code is provided below


using namespace std;

class st{
    vector<int> arr;
    int tp;
        tp = -1;
    void push(int a){
    void pop(){
    int top(){
        return arr[tp];
    int size(){
        return tp+1;
    void reset(){
        tp = -1;

int main(){
    int t;
    cin >> t;
    st s;
        vector<int> vec;
        vector<int> del;
        vector<int>::iterator itr;
        int a,n,k;
        cin >> n >> k;
        for(int i = 0; i < n; ++i){
            cin >> a;
            if(i > 0){
                while(s.size() and a > vec[]){del.push_back(;s.pop();}
        int i;
        for(i = 0; i < k && i < del.size(); ++i){
            itr = vec.begin()+del[i]-i;
        if(i != k){
            while(i < k){
                itr = vec.end()-i;
        for(i = 0; i < vec.size(); ++i) cout << vec[i] << " ";
        cout << endl;
    return 0 ;

asked 04 Jun '18, 06:25

ay2306's gravatar image

accept rate: 11%

first of all post the question for which u implemented this code.

(04 Jun '18, 15:04) gyanendra3713★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 04 Jun '18, 06:25

question was seen: 91 times

last updated: 05 Jun '18, 18:24