這篇文章主要介紹“C語言中鏈式存儲隊列的實現(xiàn)方法”,在日常操作中,相信很多人在C語言中鏈式存儲隊列的實現(xiàn)方法問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”C語言中鏈式存儲隊列的實現(xiàn)方法”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習吧!
創(chuàng)新互聯(lián)建站是專業(yè)的青秀網(wǎng)站建設(shè)公司,青秀接單;提供成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行青秀網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
#include <iostream> #include <assert.h> using namespace std; typedef struct node { int data; struct node *next; }NODE; typedef struct queue { NODE* head; NODE* tail; }QUEUE; QUEUE* create_queue() { QUEUE* queue = new QUEUE; queue->head = NULL; queue->tail = NULL; return queue; } NODE* create_node(int data) { NODE* node = new NODE; node->data = data; node->next = NULL; return node; } void queue_push(QUEUE* queue,int data) { NODE* node = create_node(data); if(queue->tail == NULL) { queue->tail = node; queue->head = node; } else { queue->tail->next = node; queue->tail = node; } } NODE* destroy_node(NODE* node) { NODE* next = node->next; delete node; return next; } int queue_pop(QUEUE* queue) { if(queue->head == NULL) { assert(false); } int data = queue->head->data; queue->head =destroy_node(queue->head); if(queue->head == NULL) { queue->tail = NULL; } return data; } int queue_size (QUEUE* queue) { int size = 0; NODE* node = NULL; for(node=queue->head; node;node=node->next) { size++; } return size; } void clear(QUEUE* queue) { while(queue->head) { queue->head = destroy_node(queue->head); } queue->tail = NULL; } void destroy_queue(QUEUE* queue) { clear(queue); delete queue; } bool queue_empty(QUEUE* queue) { if( (queue->head==NULL) && (queue->tail==NULL)) { return true; } return false; } int main() { QUEUE* queue = create_queue(); cout<<"input number: "; for(int i=0;i<10;i++) { queue_push(queue,i); cout<<i<<" "; } cout<<endl; //queue_pop(queue); // cout<<"output number:"; while(! queue_empty(queue)) { cout<<queue_pop(queue)<<" "; } cout<<endl; destroy_queue(queue); return 0; }
到此,關(guān)于“C語言中鏈式存儲隊列的實現(xiàn)方法”的學(xué)習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習,快去試試吧!若想繼續(xù)學(xué)習更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
本文題目:C語言中鏈式存儲隊列的實現(xiàn)方法
當前路徑:http://muchs.cn/article12/gededc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、做網(wǎng)站、動態(tài)網(wǎng)站、微信公眾號、靜態(tài)網(wǎng)站、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)