隊列的順序儲存表示---數組實現

來源:互聯網
上載者:User

標籤:

#define MaxSize 10typedef struct Node{    ElementType *Array;    int front;    int rear;} *Queue;QueueCreateQueue( int MaxSize ){    Queue PtrQ;    PtrQ = malloc(sizeof(struct Node ));    if(PtrQ == NULL)        printf("out of space ");    PtrQ->Array = malloc(sizeof( ElementType ) * MaxSize );    if(PtrQ == NULL )        printf("out of space ");    PtrQ->front = 0;    PtrQ->rear = 0;    return PtrQ;}int IsFull( Queue PtrQ ){    return (rear+1) % MaxSize == front;}voidAddQ(ElementType X, Queue PtrQ){    if( IsFull( PtrQ ) )    {        printf("隊列滿");        return;    }    PtrQ->rear = (Q->rear + 1) % MaxSize;    PtrQ->Array[PtrQ->rear] = X;}intIsEmpty(Queue PtrQ ){    return PtrQ->rear == PtrQ->front;}ElementTypeDeleteQ( Queue PtrQ ){    if( IsEmpty( PtrQ ) )    {        printf("隊列空");        return;    }    PtrQ->front = (PtrQ->front + 1) % MaxSize;    return PtrQ->Array[PtrQ->front];}
View Code

 

隊列的順序儲存表示---數組實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.