資料結構 佇列

2021-09-11 20:29:57 字數 1013 閱讀 8325

佇列特性:佇列:fifo(先進先出)

佇列可由順序表或者鍊錶實現:

陣列實現

//初始化

object queue;

int size;

int front=0;

int back=0;

queuebulid(int length)

//入隊

public void enqueue(object element)

//出隊

public object dequeue()

鍊錶實現
//初始化

private int listsize;

private node listtop;

private node listtail;

class node

public node(object data, node next)

}//入隊

public void linkedenqueue(object element)else

listsize++;

}//出隊

public object linkeddequeue()

return result;

}

迴圈佇列

普通佇列在入隊和出隊的過程中會存在前面的資料出隊了,後面繼續在入隊最後造成隊滿了,但是前面已出隊資料所佔的位址無法讓後面入隊資料所占用,這會造成資料「假溢位」,造成資源的浪費。為了解決這一問題,設計出迴圈佇列。

//初始化

int front;

int rear;

object queuelist;

int size;

public circlequeue(int maxlen)

//入隊

public void enqueue(object element)

//出隊

public object dequeue()

資料結構 佇列

一 佇列的迴圈陣列實現。1 初始化 空佇列。令rear front 0。2 入佇列 約定rear指向佇列尾元素的下乙個位置。入佇列時,先判斷佇列是否已滿,而後將array rear x 然後rear 3 出佇列 約定front指向佇列的首元素位置。出佇列時,先判斷佇列是否為空,而後返回隊首元素re ...

資料結構 佇列

資料參考自 資料結構c 語言描述 佇列是一種先進先出的資料結構,這與棧正好相反。下例是簡單的queue實現 queue.h檔案 ifndef queue h define queue h include include 資料元素結構 自定義 struct datatype 佇列元素最大數 const...

資料結構 佇列

code for fun created by dream whui 2015 1 25 include stdafx.h include include using namespace std define true 1 define false 0 define ok 1 define erro...