佇列輸出楊輝三角
阿新 • • 發佈:2018-12-17
#include "queue.h" int main() { int n = 8; QueuePtr Q = InitQueue(); //初始化 int s = 0, t; EnQueue(Q, 0);//入隊 EnQueue(Q, 1); printf(" 1"); putchar('\n'); for (int i = 2; i <= n; i++) { for (int m = (n - i); m > 0; m--) printf(" "); EnQueue(Q, 0); for (int j = 1; j <= i; j++) { DeQueue(Q, &t);刪除隊頭元素並賦值給t s = GetHead(Q);//返回隊頭元素 printf("%2d ", s + t); EnQueue(Q, s + t); } putchar('\n'); } system("pause"); return 0; }