鏈佇列C 實現

2021-06-29 15:07:22 字數 1315 閱讀 2923

鏈佇列時建立在單鏈表的基礎之上的。由於是動態分配節點記憶體,所以無需判滿。

鏈佇列的形式如下:

1、佇列空

2、佇列存在資料

下面介紹下c++實現的鏈佇列,vc6下除錯通過。

1、檔案組織

2、lq.h鏈佇列類的說明

[cpp]view plain

copy

print?

#ifndef _lq_h_

#define _lq_h_

typedef

intdatatype;  

struct

node                 

//佇列節點

;  class

lq  

;  #endif

3、lq.cpp鏈佇列的定義

[cpp]view plain

copy

print?

#include 

#include "lq.h"

using

namespace

std;  

lq::lq()  

lq::~lq()  

}  void

lq::push(datatype var)  

else

tail = ptr;  

}  void

lq::pop()  

}  datatype lq::front()  

bool

lq::isempty()    

4、main.cpp

[cpp]view plain

copy

print?

#include 

#include "lq.h"

using

namespace

std;  

intmain()  

for(i=0;i<200;i++)  

}  if(exp.isempty())  

return

0;  

鏈佇列之C 實現

鏈佇列時建立在單鏈表的基礎之上的。由於是動態分配節點記憶體,所以無需判滿。鏈佇列的形式如下 1 佇列空 2 佇列存在資料 下面介紹下c 實現的鏈佇列,vc6下除錯通過。1 檔案組織 2 lq.h鏈佇列類的說明 ifndef lq h define lq h typedef int datatype ...

c語言 鏈佇列的實現

鏈佇列及其操作實現.cpp 定義控制台應用程式的入口點。include stdafx.h include include includeusing namespace std typedef struct qnode qnode,queueptr typedef struct linkqueue 函...

python實現鏈佇列

在寫鏈佇列之前,我們需要知道佇列元素進出的原則為 先進先出 class node 結點類 def init self,elem self.elem elem 資料域,用來存放資料元素 self.next none 指標域,指向下乙個結點 class queue 佇列 def init self 佇列...