順序佇列及鏈佇列的基本操作實現
阿新 • • 發佈:2019-02-03
一、實驗目的
1、熟練佇列的結構特點,掌握佇列的順序儲存和鏈式儲存結構和實現。
2、 學會使用佇列解決實際問題。
二、實驗內容自己確定結點的具體資料型別和問題規模:
分別建立一個順序佇列和鏈佇列,實現佇列的入隊和出隊操作。
三、實驗步驟
1、依據實驗內容分別說明實驗程式中用到的資料型別的定義;
2、相關操作的演算法表達;
3、完整程式;
4、總結、執行結果和分析。
5、總體收穫和不足,疑問等。
四、實驗程式碼
1、順序佇列
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include<iostream>using namespace std;const |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
#include<iostream>using namespace std;struct Node{ int data; Node *next;};class LinkQueue{public: LinkQueue(); ~LinkQueue();//解構函式,釋放鏈佇列中各結點的儲存空間 void EnQueue(int x);//將元素x入隊 int DeQueue();//將隊頭元素出隊 int GetQueue();//取鏈佇列的隊頭元素 int Empty(); private: Node *front, *rear;//隊頭和隊尾元素};LinkQueue::LinkQueue(){ Node *s=NULL; s=new Node; s->next=NULL; front=rear=s;}LinkQueue::~LinkQueue(){ Node *p=NULL; while(front!=NULL) { p=front->next; delete front; front=p; }}void LinkQueue::EnQueue( |