隊列的鏈式儲存結構的實現1 —— 建立銷毀判斷滿空入隊,鏈式滿空
// Filename : list_queue.c// Author : LupingChen// Data : 2015.05.30// Content : create\destory\full\empty\push#include <stadio.h>#include <stdlib.h>//定義節點資料類型typedef struct Node { int data;//資料 struct Node* next;//記錄下一節點地址} Node;//定義隊列資料類型typedef struct { Node* head;//頭指標} Queue;//判斷隊列是否為滿int full(Queue* pq);//判斷隊列是否為空白int empty(Queue* pq);//入隊void push(Queue* pq, data);//遍曆void travel(Queue* pq);int main(){ //建立,系統銷毀 Queue queue; queue.head= NULL; return 0;}//判斷隊列是否為滿int full(Queue* pq){ return 0;}//判斷隊列是否為空白int empty(Queue* pq){ return NULL == pq->head;}//入隊void push(Queue* pq, data){ //建立節點 Node* pn = (Node* )malloc(sizeof(Node)); pn->data = data; pn->next = NULL; //掛載節點 //空隊列掛載 if (empty) { pq->head = pn; } //非空隊列掛載 Node* p = pq->head; while (p->next != NULL) { p = p->next; } p->next = pn;}//遍曆void travel(Queue* pq){ printf("隊列中元素有:"); Node* p = pq->head; while (p != NULL) { printf("%d ", p->data); p = p->next; } printf("\n");}