#include<iostream>
using namespace std;
struct list
{
int data; struct list *next;
};
class Stack
{
struct list *ptrf,*ptrb;
public:
Stack()
{
ptrf=ptrb=NULL;
}
void push(int x)
{
struct list *newnode=new struct list;
newnode->data=x;
newnode->next=NULL;
if(ptrb==NULL)
ptrf=ptrb=newnode;
else
{
ptrb->next=newnode;
ptrb=newnode;
}
}
int pop()
{
//struct list *top;
int value;
value=ptrf->data;
//top=ptrf;
ptrf=ptrf->next;//因為19行代碼說是NULL,那麼這裡的ptrf不就也為NULL了?
//delete top;
return value;
}
};
void main()
{
Stack A; int i;
int arr[]={5,2,8,1,4,3,9,7,6};
cout<<"入隊順序:";
for(i=0;i<9;i++)
{
cout<<arr[i]<<" ";
A.push(arr[i]);
}
cout<<endl<<"出隊順序:";
for(i=0;i<9;i++)
cout<<A.pop()<<" ";
cout<<endl;
system("pause");
}