标签:next == include printf sizeof turn bre ext new
1 #include"stdio.h" 2 #include"stdlib.h" 3 typedef int QueueElementType; 4 typedef struct Node 5 { 6 QueueElementType data; 7 struct Node *Next; 8 }LinkQueueNode; 9 typedef struct 10 { 11 LinkQueueNode *font; 12 LinkQueueNode *rear; 13 }LinkQueue; 14 // 将Q初始化空队列 15 int InitQueue(LinkQueue *Q) 16 { 17 Q->font=(LinkQueueNode *)malloc(sizeof(LinkQueueNode)); 18 if(Q->font!=NULL) 19 { 20 Q->rear=Q->font;/* 同时指向头结点*/ 21 Q->font->Next=NULL; 22 return 1; 23 } 24 else return 0; /*溢出*/ 25 } 26 //将X插入到队列Q中 27 int EnterQueue(LinkQueue *Q,QueueElementType x) 28 { 29 LinkQueueNode *NewNode; 30 NewNode=(LinkQueueNode *)malloc(sizeof(LinkQueueNode)); 31 if(NewNode!=NULL) 32 { 33 NewNode->data=x; 34 NewNode->Next=NULL; 35 Q->rear->Next=NewNode; 36 Q->rear=NewNode; 37 return 1; 38 } 39 else return 0; 40 } 41 int DeleteQueue(LinkQueue *Q,QueueElementType *x) 42 { 43 LinkQueueNode * p; 44 if(Q->font==Q->rear) 45 return 0; 46 p=Q->font->Next; 47 Q->font->Next=p->Next; 48 if(Q->rear==p) 49 Q->rear=Q->font; 50 *x=p->data; 51 printf("%d",*x); 52 free(p); 53 return 1; 54 } 55 int main() 56 { 57 int x,a; 58 LinkQueue S; 59 InitQueue(&S); 60 printf("请输入选项: "); 61 scanf("%d",&a); 62 while(1) 63 { 64 if(a==0) 65 break; 66 switch(a) 67 { 68 case 1: 69 { 70 while(1) 71 { 72 scanf("%d",&x); 73 if(x==0) 74 break; 75 EnterQueue(&S,x); 76 } 77 }break; 78 case 2: { 79 DeleteQueue(&S,&x); 80 };break; 81 default : printf("error"); 82 }printf("请输入选项: "); 83 scanf("%d",&a); 84 }return 0; 85 }
标签:next == include printf sizeof turn bre ext new
原文地址:http://www.cnblogs.com/HandC/p/7672832.html