日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

20.链式队列

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 20.链式队列 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

運行截圖:

完整代碼:

1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define datatype int 5 6 typedef struct queue 7 { 8 datatype data; 9 struct queue *pNext; 10 }Queue,*PQueue; 11 12 //入隊 從尾部入,從頭部出 13 PQueue enq(PQueue phead, datatype data) 14 { 15 PQueue pnew = (PQueue)malloc(sizeof(Queue)); 16 pnew->data = data; 17 pnew->pNext = NULL; 18 if (phead == NULL) 19 { 20 phead = pnew;//直接插入 21 } 22 else 23 { 24 PQueue ptemp = phead; 25 //循環到尾部 26 while (ptemp->pNext != NULL) 27 { 28 ptemp = ptemp->pNext; 29 } 30 ptemp->pNext = pnew;//尾部插入 31 } 32 return phead; 33 } 34 35 //出隊 36 PQueue deq(PQueue phead, datatype *pdata) 37 { 38 if (phead == NULL) 39 { 40 return NULL; 41 } 42 else 43 { 44 *pdata = phead->data;//獲取彈出的數據 45 PQueue ptemp = phead->pNext; 46 free(phead); 47 phead = ptemp; 48 } 49 } 50 51 //顯示 52 void show(PQueue phead) 53 { 54 if (phead == NULL) 55 { 56 return; 57 } 58 else 59 { 60 printf("%5d", phead->data); 61 show(phead->pNext);//遞歸調用 62 } 63 } 64 65 void main() 66 { 67 Queue *phead = NULL; 68 for (int i = 0; i < 10; i++) 69 { 70 phead = enq(phead, i); 71 printf("\nqueue"); 72 show(phead); 73 } 74 75 while (phead != NULL) 76 { 77 datatype data; 78 phead = deq(phead, &data); 79 printf("\ndequeue%d", data); 80 printf("\nqueue"); 81 show(phead); 82 } 83 84 system("pause"); 85 }

?

轉載于:https://www.cnblogs.com/xiaochi/p/8400126.html

總結

以上是生活随笔為你收集整理的20.链式队列的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。