#include <iostream>
using namespace std;
class mylist
{
public:
int data;
mylist *next;
};
int main()
{
mylist *front=0,*rear=0,*newptr=0,*tempptr=0;
int a,value;
for(;true;)
{
cout<<"Add node?(1)yes,(0)No."<<endl;
cin>>a;
if(a==1)
{
cout<<"Key in a number value:"<<endl;
cin>>value;
newptr = new mylist;
newptr->data = value;
if(rear==0)
{
rear = newptr;
rear->next = 0;
}
else
{
newptr->next = 0;
rear->next = newptr;
rear = newptr;
}
if(front==0){front = rear;}
}
else if(a==0)
{
if(front==0)cout<<"list empty"<<endl;
else
{
tempptr = front;
front = front->next;
value = tempptr->data;
delete tempptr;
cout<<"the value is "<<value<<endl;
}
}
else{cout<<"Wrong input"<<endl;}
}
return 0;
}
留言列表