zoukankan      html  css  js  c++  java
  • 队列

    //   队列的各种实现

    #include <cstdio>
    #include <cstdlib>
    //#define _OJ_


    typedef struct Lnode
    {
        int data;
        struct Lnode *next;
    } qNode, *Queueptr;

    typedef struct
    {
        Queueptr front;
        Queueptr rear;
    }queue, *Linkqueue;

    void
    creat_queue(Linkqueue q)
    {
        q->front = q->rear = (Queueptr) malloc (sizeof(qNode));
        q->front->next = NULL;
    }


    int
    isempty(Linkqueue q)
    {
        if(q->front == q->rear)
            return 1;
        else
            return 0;
    }


    void
    Enqueue(Linkqueue q)
    {
        printf("%p ", q->rear);
        Queueptr p1;
        p1 = (Queueptr) malloc (sizeof(qNode));
        scanf("%d", &p1->data);
        printf("%d ", p1->data);
        p1->next = NULL;
        q->rear->next = p1;
        q->rear = p1;
            printf("%p ", q->rear);

    }


    int
    Dequeue(Linkqueue q)
    {
        int e;
        Queueptr p;
        p = q->front->next;
        e = p->data;
        q->front->next = p->next;
        if(q->rear == p) q->rear = q->front;
        free(p);
        return e;
    }




    int main(int argc, char const *argv[]) {
    #ifndef _OJ_  //ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif

        Linkqueue q;
        creat_queue(q);
        printf("%d ",isempty(q));
        int i, n, x;
        scanf("%d", &n);

        while (n--)
        Enqueue(q);

        while (q->rear != q->front)
        printf("%d ", Dequeue(q));







        return 0;
    }

  • 相关阅读:
    vue中封装公共方法,全局使用
    element-ui table 最后一行合计,单元格合并
    vuex 进行封装
    vue生命周期
    (转)no terminal library found
    解压
    (转)bash: make: command not found
    (转)linux 批量删除文件命令
    python
    Session
  • 原文地址:https://www.cnblogs.com/airfand/p/4921919.html
Copyright © 2011-2022 走看看