C语言 队列实现杨辉三角的打印.docx
C语言 队列实现杨辉三角的打印#include<stdio.h>#include<conio.h>#define MAXSIZE 100typedef int QueueElemType;typedef structQueueElemType elemMAXSIZE;int front;int rear;SeqQueue;void InitQueue(SeqQueue *Q)Q->front = Q->rear = 0;int EnterQueue(SeqQueue *Q, QueueElemType x)if (Q->rear + 1) % MAXSIZE = Q->front)return 0;Q->elemQ->rear = x;Q->rear = (Q->rear + 1) % MAXSIZE;return 1;int DeleteQueue(SeqQueue *Q, QueueElemType *x)if (Q->front = Q->rear)return 0;*x = Q->elemQ->front;Q->front = (Q->front + 1) % MAXSIZE;return 1;int GetHead(SeqQueue *Q, QueueElemType *x)if (Q->front = Q->rear)return 0;else*x = Q->elemQ->front;return 1;int IsEmpty(SeqQueue *Q)if (Q->front = Q->rear)printf_s("Empty!");return 1;int mainSeqQueue Q;InitQueue(&Q);EnterQueue(&Q, 1);int n, i, temp, N;int x = 1;for (n = 2;n <= 11;n+)EnterQueue(&Q, 1);for (i = 1;i <= n - 2;i+)DeleteQueue(&Q, &temp);printf_s("%5d", temp);GetHead(&Q, &x);temp = temp + x;EnterQueue(&Q, temp);DeleteQueue(&Q, &x);printf_s("%5d", x);printf_s("n");EnterQueue(&Q, 1);while (!IsEmpty(&Q)DeleteQueue(&Q, &x);printf_s("%5d", x);_getch;return 0;