链队列

    技术2022-05-20  52

    #include <stdio.h> #include <stdlib.h> typedef struct QNode {     int data;     struct QNode* next; }QNode; typedef struct QList {     struct QNode* front;     struct QNode* end; }QList; void InitQL(QList* QL) {     if(QL==NULL)         QL=(QList*)malloc(sizeof(QList));     QL->front=NULL;     QL->end=NULL; } void InsertQL(QList* QL,int value) {     QNode* p;     p=(QNode*)malloc(sizeof(QNode));     p->data=value;     if(QL->front==NULL)     {         QL->front=p;         QL->end=p;         p->next=NULL;     }     else     {         p->next=NULL;         QL->end->next=p;         QL->end=p;     } } int DeleteQL(QList* QL) {     QNode *p;     int res;     if(QL->front==NULL)     {         return -1;     }     res=QL->front->data;     p=QL->front;     if(QL->front->next==NULL)     {         QL->front=NULL;         QL->end=NULL;     }     else     {         QL->front=p->next;     }     free(p);     return res; } void Print(QList* QL) {     QNode *p;     p=QL->front;     while(p)     {         printf("%d/t",p->data);         p=p->next;     } } int main() {     QList *ML;     int i,val;     ML=(QList*)malloc(sizeof(QList));     InitQL(ML);     for(i=0;i<34;i++)     {         InsertQL(ML,i*8+3);     }     Print(ML);     printf("/n");     for(i=1;i<32;i++)     {         val=DeleteQL(ML);         printf("%d/t",val);     }     printf("/n");     Print(ML);     getchar();         return 0; }


    最新回复(0)