#include<iostream.h>
struct Stack{
int *data;
int memNum;
int size;
};
int initStack(Stack &s,int size);
void delStack(Stack &s);
int popStack(Stack &s,int &num);
int pushStack(Stack &s,int mem);
//初始化栈
int initStack(Stack &s,int size)
{
s.data=new int[size];
if(s.data==NULL)
return 0;
s.memNum=0;
s.size=size;
return 1;
}
//释放栈
void delStack(Stack &s)
{delete[] s.data;}
//弹栈
int popStack(Stack &s,int &num)
{if(s.memNum==0)
return 0;
num=s.data[--s.memNum];
return 1;
}
//压栈
int popStack(Stack &s,int mem)
{if(s.memNum==s.size)
return 0;
s.data[s.memNum++]=mem;
return 1;
}
main()
{
int i,num;
Stack newStack;
initStack(newStack, 10);
//压栈
cout<<"push integer to stack:"<<endl;
for(i=0;i<10;i++)
{cout<<i<<" ";
pushStack(newStack,i);}
cout<<endl;
//弹栈
cout<<"Reading from function popStack:"<<endl;
for(i=0;i<10;i++)
{if(popStack(newStack,num))//这里发生错误,我不会改,有谁能帮我改改
cout<<num<<" ";}
cout<<endl<<endl;
//破坏性的使用栈
for(i=10;i<20;i++)
{newStack.data[newStack.memNum++]=i;}
cout<<"Reading from struct newStack:"<<endl;
for(i=0;i<10;i++)
{ cout<<newStack.data[i]<<" ";}
cout<<endl;
for(i=10;i<20;i++)
{ cout<<newStack.data[i]<<" ";}
cout<<endl;
//释放栈
delStack(newStack);
return 0;
}
[求助]一个小错误,不会改,改了很久,都改不了