标签:div bre 元素 cst lib void enter har cstring
本周的作业要求:
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #define MAXSIZE 50 5 typedef struct 6 { 7 char a[MAXSIZE]; 8 int front; 9 int rear; 10 }SeqQueue; 11 12 int flag=0; 13 14 void deng(SeqQueue *Q); 15 16 void duiman(SeqQueue *Q) 17 { 18 printf("队满,插入失败,返回登录界面\n"); 19 deng(Q); 20 } 21 22 void duikong(SeqQueue *Q) 23 { 24 printf("队空,无元素出队,返回登陆界面\n"); 25 flag=0; 26 deng(Q); 27 } 28 29 void EnterQueue(SeqQueue *Q,char x) 30 { 31 if((Q->rear +1)%MAXSIZE==Q->front) 32 duiman(Q); 33 Q->a[Q->rear]=x; 34 Q->rear=(Q->rear+1)%MAXSIZE; 35 return; 36 } 37 38 void DeleteQueue(SeqQueue *Q) 39 { 40 char x; 41 if(Q->front==Q->rear) 42 duikong(Q); 43 x=Q->a[Q->front]; 44 Q->front=(Q->front+1)%MAXSIZE; 45 if(flag==0){ 46 flag=1; 47 DeleteQueue(Q); 48 }else 49 printf("出队的队头元素为%c\n",x); 50 deng(Q); 51 } 52 53 void ru(SeqQueue *Q) 54 { 55 printf("输入入队元素以$结束\n"); 56 char En[MAXSIZE]; 57 int i; 58 for(i=0;i<MAXSIZE;i++){ 59 scanf("%c",&En[i]); 60 if(En[i]!=‘$‘){ 61 EnterQueue(Q,En[i]); 62 } 63 else 64 break; 65 } 66 printf("入队成功!\n"); 67 deng(Q); 68 } 69 70 void InitQueue(SeqQueue *Q) 71 { 72 Q->front=Q->rear=0; 73 } 74 75 void deng(SeqQueue *Q) 76 { 77 printf("1.入队\n"); 78 printf("2.使队头元素出队,并返回它的值\n"); 79 printf("3.退出\n"); 80 int a; 81 scanf("%d",&a); 82 switch(a) 83 { 84 case 1: 85 system("CLS"); 86 ru(Q); 87 case 2: 88 system("CLS"); 89 DeleteQueue(Q); 90 case 3: 91 exit(0); 92 default: 93 printf("输入不合法,请重新输入\n"); 94 deng(Q); 95 } 96 } 97 98 99 int main() 100 { 101 SeqQueue Q; 102 InitQueue(&Q); 103 deng(&Q); 104 105 return 0; 106 }
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #define MAXSIZE 50 5 typedef struct 6 { 7 char a[MAXSIZE]; 8 int front; 9 int rear; 10 }SeqQueue; 11 12 int flag=0,tag=0; 13 14 15 void deng(SeqQueue *Q); 16 17 void duiman(SeqQueue *Q) 18 { 19 printf("队满,插入失败,返回登录界面\n"); 20 deng(Q); 21 } 22 23 void duikong(SeqQueue *Q) 24 { 25 printf("队空,无元素出队,返回登陆界面\n"); 26 flag=0; 27 deng(Q); 28 } 29 30 void EnterQueue(SeqQueue *Q,char x) 31 { 32 if(tag==1&&Q->front==Q->rear) 33 duiman(Q); 34 Q->a[Q->rear]=x; 35 Q->rear=(Q->rear+1)%MAXSIZE; 36 return; 37 } 38 39 void DeleteQueue(SeqQueue *Q) 40 { 41 char x; 42 if(tag==0&&Q->front==Q->rear) 43 duikong(Q); 44 x=Q->a[Q->front]; 45 Q->front=(Q->front+1)%MAXSIZE; 46 if(flag==0){ 47 flag=1; 48 DeleteQueue(Q); 49 }else{ 50 tag=0; 51 printf("出队的队头元素为%c\n",x); 52 } 53 deng(Q); 54 } 55 56 void ru(SeqQueue *Q) 57 { 58 printf("输入入队元素以$结束\n"); 59 char En[MAXSIZE]; 60 int i; 61 for(i=0;i<MAXSIZE;i++){ 62 scanf("%c",&En[i]); 63 if(En[i]!=‘$‘){ 64 EnterQueue(Q,En[i]); 65 } 66 else 67 break; 68 } 69 tag=1; 70 printf("入队成功!\n"); 71 deng(Q); 72 } 73 74 void InitQueue(SeqQueue *Q) 75 { 76 Q->front=Q->rear=0; 77 } 78 79 void deng(SeqQueue *Q) 80 { 81 printf("1.入队\n"); 82 printf("2.使队头元素出队,并返回它的值\n"); 83 printf("3.退出\n"); 84 int a; 85 scanf("%d",&a); 86 switch(a) 87 { 88 case 1: 89 system("CLS"); 90 ru(Q); 91 case 2: 92 system("CLS"); 93 DeleteQueue(Q); 94 case 3: 95 exit(0); 96 default: 97 printf("输入不合法,请重新输入\n"); 98 deng(Q); 99 } 100 } 101 102 103 int main() 104 { 105 SeqQueue Q; 106 InitQueue(&Q); 107 deng(&Q); 108 109 return 0; 110 }
标签:div bre 元素 cst lib void enter har cstring
原文地址:http://www.cnblogs.com/xzt6/p/5991459.html