chenxie95 / SJTU_C-_Cource

上交2022小学期 程序设计思想 答疑论坛
1 stars 0 forks source link

求助 栈这道题的data哪里来的,怎么一直都是0 #20

Open echoJzjjy opened 2 years ago

echoJzjjy commented 2 years ago

错误说明,data那里输出一直都是pop 0 success  class mystack {     private:     int *arr;     int size;     int tail;

    public:     mystack(int x):size(x),tail(0),arr(new int[5]){}     mystack():size(100),tail(0),arr(new int[100]){}

    int isempty()     {         if(tail==0) return 1;         else return 0;     }     int isfull()     {         if(tail>=size) return 1;         else return 0;     }     int push(int i)     {         if(tail<size)         {           arr[tail] = i;           tail ++;           return 1;         }         else return 0;     }     int pop(int data)     {         if(tail>0)         {             data = arr[tail];             tail --;             return 1;         }         else          return 0;     } };

echoJzjjy commented 2 years ago

如图: 1f633b35c9f1f04850ef0ab5307dc1a 4d549f3bbcbcff68060192f163da9f8

echoJzjjy commented 2 years ago

这个data打印出来就是0,不动main没法改这个data啊……

Liangzheng-ZL commented 2 years ago

不需要更改main,在写pop时定义引用变量,调用时指向data