本題與上題本質上相同現用類C語言編寫入隊和出隊算法
()void EnQueue (LinkedList rear ElemType x)
// rear是帶頭結點的循環鏈隊列的尾指針本算法將元素x插入到隊尾
{ s= (LinkedList) malloc (sizeof(LNode)); //申請結點空間
s>data=x; s>next=rear>next; //將s結點鏈入隊尾
rear>next=s; rear=s; //rear指向新隊尾
}
()void DeQueue (LinkedList rear)
// rear是帶頭結點的循環鏈隊列的尾指針本算法執行出隊操作操作成功輸出隊頭元素否則給出出錯信息
{ if (rear>next==rear) { printf(隊空\n); exit();}
s=rear>next>next; //s指向隊頭元素
rear>next>next=s>next; //隊頭元素出隊
printf (出隊元素是s>data);
if (s==rear) rear=rear>next; //空隊列
free(s);
}
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/22699.html