資料結構 佇列

2021-06-21 21:39:34 字數 930 閱讀 9777

資料參考自《資料結構c++語言描述》

佇列是一種先進先出的資料結構,這與棧正好相反。

下例是簡單的queue實現

queue.h檔案

#ifndef _queue_h_

#define _queue_h_

#include

#include

//資料元素結構(自定義)

struct datatype

;//佇列元素最大數

const int maxqsize = 50;

//佇列

class queue

;#endif

queue.cpp檔案

#include "queue.h"

using namespace std;

queue::queue():_front(0),_rear(0),_count(0)

queue::~queue()

void queue::insert(const datatype & item)

datatype queue::remove()

void queue::clear()

datatype queue::front() const

int queue::length() const

bool queue::isempty() const

bool queue::isfull() const

測試#include "stdafx.h"

#include "queue.h"

using namespace std;

int _tmain(int argc, _tchar* argv)

現實中顧客排隊可以充分體現出佇列的先進先出理念。排在隊首的顧客將理所當然地首先完成交易,然後接下來的第二位顧客便成了隊首,如此迴圈,直至所有顧客都完成交易(即隊列為空)。

資料結構 佇列

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

資料結構 佇列

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...

資料結構 佇列

佇列是一種有序的線性表,佇列的兩端分別稱為隊首和隊尾。佇列只允許在隊尾進行插入操作,在隊首進行刪除操作。插入元素稱為入隊,刪除元素稱為出隊。佇列常用鍊錶或陣列來實現。include include using namespace std define max 1000 佇列定義 struct ele...