線性表的儲存方式有順序儲存和鏈式儲存,前兩篇均是佇列順序儲存的例子,以下是鏈式儲存的**:
#include
<
string
.h>
#include
struct node ;
struct fifo ;
//初始化佇列
void init(struct fifo *fifo)
//進隊
int put(struct fifo *fifo, int value)
//出隊
int get(struct fifo *fifo)
struct node* node = fifo->front->next;
int value = node->
data;
fifo->front->next = node->next;
free(node);
node =
null;
return value;
}//銷毀佇列
void destroy(struct fifo *fifo)
free(fifo->front);
fifo->front =
null;
fifo->rear =
null;
}//清空佇列
void clear(struct fifo *fifo)
fifo->rear = fifo->front;
}
佇列鏈式儲存
ifndef status h define status h define false 1 define true 1 define ok 1 define error 0 typedef int elemtype typedef int status endif ifndef stack h d...
佇列的鏈式儲存
include include include typedef int elemtype typedef struct qnodequeuenode,queuenodeptr typedef struct qlistlistqueue,listqueueptr listqueueptr initqu...
佇列的鏈式儲存
include include 經典的佇列,使用鏈式儲存實現 佇列的基本特點就是一端是執行出列操作,一端是執行入列操作 typedef struct nodenode typedef structqueue void outqueue queuep myqueue void displayqueue...