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;
    }

  • 相关阅读:
    Elasticsearch
    Docker
    Python 目录
    淘宝
    MyBatis
    Docker 安装ubuntu服务器
    goodrain云平台 mysql主从同步应用创建
    flask入门
    virtualenv
    进程 线程(二)
  • 原文地址:https://www.cnblogs.com/airfand/p/4921919.html
Copyright © 2011-2022 走看看