因本人英语不好所以使用拼音代替
写作不易请点赞
#includeusing namespace std; typedef struct xuhuandl{ int data; xuhuandl*next; }xuhuandl,*Xuhuandl; void chushua(Xuhuandl &front,Xuhuandl &rear);//初始化队列 void pankong(Xuhuandl &front,Xuhuandl &rear);//检查队列是否为空 void qingkong(Xuhuandl &front,Xuhuandl &rear);//清空队列 void rud(Xuhuandl &front,Xuhuandl &rear,int nr);//入队 void chud(Xuhuandl &front,Xuhuandl &rear);//出队 void qudshoys(Xuhuandl &front,Xuhuandl &rear);//取队首元素 int main(){ Xuhuandl front,rear;//头尾指针 int xz; int nr; front=new xuhuandl; rear=new xuhuandl; for(int i=0;i<10;){ cout<<"1,初始化队列 2,检查队列是否为空"<<"n"; cout<<"3,清空队列 4,入队"<<"n"; cout<<"5,出队 6,取队首元素"<<"n"; cin>>xz; if(xz==1)chushua(front,rear); if(xz==2)pankong(front,rear); if(xz==3)qingkong(front,rear); if(xz==4){ cout<<"请输入内容"<<"n"; cin>>nr; rud(front,rear,nr); } if(xz==5)chud(front,rear); if(xz==6)qudshoys(front,rear); } } void chushua(Xuhuandl &front,Xuhuandl &rear){ front=NULL; rear=NULL; cout<<"初实化成功"<<"n"; } void pankong(Xuhuandl &front,Xuhuandl &rear){ if(front==NULL||front==rear) cout<<"为空"<<"n"; else cout<<"不为空"<<"n"; } void qingkong(Xuhuandl &front,Xuhuandl &rear){ front=NULL; rear=NULL; cout<<"已清空"<<"n"; } void rud(Xuhuandl &front,Xuhuandl &rear,int nr){ Xuhuandl p; p=new xuhuandl; if(front==NULL){ p->data=nr; front=p; rear=p; }else{ p->data=nr; rear->next=p; rear=p; } } void chud(Xuhuandl &front,Xuhuandl &rear){ if(front==rear&&front!=NULL){ Xuhuandl p; p=new xuhuandl; cout<<"数为"< data<<"n"; p=front->next; front=NULL; rear=NULL; return; } if(front==NULL||rear==NULL){ cout<<"队列为空无法输出"<<"n"; return; } Xuhuandl p; p=new xuhuandl; cout<<"数为"< data<<"n"; p=front->next; front=p; } void qudshoys(Xuhuandl &front,Xuhuandl &rear){ if(front==NULL){ cout<<"队首为空无法输出"<<"n"; return; }else{ cout<<"队首为"< data<<"n"; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)