⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lqueue.c

📁 初级入门数据结构的排序等8个小程序,有兴趣的看看哈!我的作业,呵呵!
💻 C
字号:
/*链队列*/
#include <stdio.h>
typedef int datatype;
typedef struct node
{
    datatype data;
    struct node *next;        
}QNode;
typedef struct 
{
    QNode *front,*rear;       
}LQueue;

LQueue *Init_LQueue()
{
    QNode *p;
    LQueue *q;
    p=(QNode *)malloc(sizeof(QNode));
    q=(LQueue *)malloc(sizeof(LQueue));
    p->next=NULL;
    q->front=p;
    q->rear=p;
    return q;      
}

void In_LQueue(LQueue *q,datatype x)
{
    QNode *p;
    p=(QNode *)malloc(sizeof(QNode));
    p->data=x;
    p->next=NULL;
    q->rear->next=p;;
    q->rear=p;    
}

int Empty_LQueue(LQueue *q)
{
    if(q->rear==q->front) return 1;
    else return 0;    
}

int Out_LQueue(LQueue *q,datatype *x)
{
    QNode *p;
    if(Empty_LQueue(q))
    {
       printf("队空");
       return 0;                
    }
    else
    {
        p=q->front->next;
        q->front->next=p->next;
        *x=p->data;
        free(p);
        if(q->front->next==NULL)
            q->rear=q->front;
        }                         
}
main()
{
    LQueue *L;
    datatype y;
    L=Init_LQueue();
    scanf("%d",&y);
    while(y!=0)
    {
        In_LQueue(L,y);
        scanf("%d",&y);
    }
    while(!Empty_LQueue(L))
    {
        if(Out_LQueue(L,&y))
            printf("%d\t",y);
        else break;
    }
    getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -