c 資料結構 鏈式佇列

2021-07-25 04:19:29 字數 1049 閱讀 5570

1.標頭檔案:

# includeusing namespace std;

struct linknode

linknode(const int x,linknode* ptr=null):date(x),link(ptr){}

};class linkedqueue //建構函式:構造空佇列

void makeempty(); //將表置空

~linkedqueue() //析構函式:(*不能直接用delete清空全部儲存空間的析構函式往往需要呼叫另乙個函式幫助清空)

bool enqueue(int& x); //進隊函式

bool dequeue(int& x); //出隊函式

bool getfront(int& x); //取隊頭

bool isempty() //判斷表空

int getsize(); //求佇列元素個數

friend ostream& operator<<(ostream& ostr,linkedqueue& q); //輸出運算子過載

};

2.原始檔:

# include# include"linkedqueue.h"

using namespace std;

void linkedqueue::makeempty()

}bool linkedqueue::enqueue(int& x)

else

return true;

}bool linkedqueue::dequeue(int& x)

return true;

}bool linkedqueue::getfront(int& x)

}int linkedqueue::getsize()

return count;

}ostream& operator<<(ostream& ostr,linkedqueue& q)

return ostr;

}

資料結構 鏈式佇列 C

用鍊錶搭建的棧與佇列相對簡單,佇列的特點是先進先出,不囉嗦了,由於 比較簡單,相信光顧的人不會太多,下面直接貼 標頭檔案1 ifndef queueli h 2 define queueli h 34 template 5class queue625 26 listnode front 27 lis...

資料結構鏈式佇列

對佇列進行以下操作 1.入佇列 2.出佇列 3.取隊首元素 佇列先進先出,要想實現入佇列,從隊尾插入元素 要想實現出佇列,從隊首刪除元素。在這裡,我們定義頭尾指標,首先對空佇列插入元素,讓頭指標等於尾指標,如果非空,依然讓頭指標指向隊首,尾指標指向要插入的元素。刪除元素時,直接讓頭指標指向下乙個元素...

資料結構之鏈式佇列

我們實現了順序佇列,包括優化,現在我們再來學習下鏈式佇列。注 這裡還是要包含前面我們實現的鏈式鍊錶的標頭檔案和實現檔案。第十個例子,鏈式佇列的實現 標頭檔案 ifndef linkqueue h define linkqueue h typedef void linkqueue linkqueue ...