队列: #include"stdio.h" #include"stdlib.h" #include"iostream.h" #define OK 1 #define ERROR 0 typedef int status; typedef struct Qnode{ char data; struct Qnode *next; }Qnode, *queueptr; typedef struct{ queueptr front; queueptr rear; }linkqueue; status ini(linkqueue &Q) //初始化 { Q.front=Q.rear=(queueptr)malloc(sizeof(Qnode)); if(!Q.front) exit(0); Q.front->next=NULL; return OK; } status en(linkqueue &Q,char e) //进队 { Qnode *p; p=(queueptr)malloc(sizeof(Qnode)); if(!p) exit(0); p->data=e; p->next=NULL; Q.rear->next=p; Q.rear=p; return OK; } status de(linkqueue &Q,char &e) //出队 { if(Q.front==Q.rear) return ERROR; queueptr p; p=Q.front->next; e=p->data; Q.front->next=p->next; if(Q.rear==p) Q.rear=Q.front; free(p); return OK; } void main() { linkqueue Q; ini(Q); char in; char out; char temp; int flag=0; printf("输入要入队的元素(回车间隔,#结束): \n"); do{ scanf("%c",&in); en(Q,in); }while(in!='#'); printf("输入要查找的元素: "); cin>>out; //此处C的输入应为 scanf("%c",&out); do{ de(Q,temp); if(temp==out) { printf("查找成功!\n "); flag=1; } }while(de(Q,temp)!=0); if(flag==0) printf("队列中无此元素!\n "); } 本文来源:https://www.wddqw.com/doc/014480ab01d276a20029bd64783e0912a2167cf3.html