#include<stdio.h>
#include <stdlib.h>
typedef struct Linknode{
int data;
struct Linknode *next;
}Linknode;
typedef struct{
Linknode *front;
Linknode *rear;
}Linksqueue;
bool Initsqueue (Linksqueue &s)
{
(Linknode*)malloc(sizeof(Linknode));
s.front=s.rear=(Linknode*)malloc(sizeof(Linknode));
s.front->next==NULL;
return 0;
}
bool insert(Linksqueue &s,int x){ //插入元素,入队
Linknode *a=(Linknode *)malloc(sizeof(Linknode));
a->data=x;
a->next=NULL;
s.rear->next=a;
s.rear=a;
printf("插入成功\n");
return true;
}
bool look(Linksqueue &s){ //查看元素
if(s.front==s.rear)
{
printf("队列为空\n");
return false;
}
Linknode *p;
p=s.front->next;
for(int i=1;p!=NULL;i++)
{
printf("第%d个元素为%d\n",i,p->data);
p=p->next;
}
}
bool Delete (Linksqueue &s,int &x) //删除元素,出队
{
if(s.front==s.rear){
printf("队列为空\n");
return false;
}
x=s.front->next->data;
printf("出队元素为%d\n",x);
s.front->next=s.front->next->next;
return true;
}
bool empty(Linksqueue &s) //判断队列是否为空;
{
if(s.front==s.rear){
printf("队列为空\n");
return true;
}
else
return false;
}
int main(){
Linksqueue s;
Initsqueue(s);
insert (s,1);
insert (s,2);
insert (s,3);
insert (s,4);
insert (s,5);
insert (s,6);
look(s);
int x;
Delete (s,x);
look(s);
empty (s);
return 0;
}
03-14
181
09-18
843