隊列的鏈式儲存結構的實現3——完結編,隊列鏈式

來源:互聯網
上載者:User

隊列的鏈式儲存結構的實現3——完結編,隊列鏈式

//  Filename    :   list_queue.c//  Authot      :   LupingChen//  Data        :   2014.06.01//  Content     :   main\clear#include <stdio.h>#include <stdlib.h>//定義節點資料類型typedef struct Node {    int data;//節點資料    struct Node* next;//記錄下一節點地址} Node;//定義隊列資料類型typedef struct {    Node* head;//頭指標}//清除隊列所有元素void clear(Queue* pq);int main(void){    push(&queue, 11);    travel(&queue);    push(&queue, 22);    travel(&queue);    push(&queue, 33);    travel(&queue);    printf("%s\n", empty(&queue)?"隊列為空白":"隊列沒空");    printf("%s\n", full(&queue)?"隊列為滿":"隊列沒滿");        printf("-----------------------------------------\n");    travel(&queue);    printf("出隊元素是%d\n",pop(&queue));    printf("隊首元素是:%d\n", get_head(&queue));    printf("隊尾元素是:%d\n", get_tail(&queue));    printf("隊列元素個數是:%d\n", size(&queue));    clear(&queue);    return 0;}//清除隊列所有元素void clear(Queue* pq){    while (pq->head != NULL)    {        Node* p = pq->head;        pq->head = p->next;        free(p);        p = NULL;    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.