zoukankan      html  css  js  c++  java
  • 队列链式存储

    /**
     * 队列--链式存储
     **/
    #include <stdlib.h>
    #include <iostream.h>
    
    #define OK 1
    #define ERROR 0
    
    typedef struct node {         //链式队列的结点结构
        int item;                  //队列的数据元素类型
        struct node *next;        //指向后继结点的指针
    }NODE;
    
    typedef struct queue{      //链式队列
        NODE *front;           //队头指针
        NODE *rear;            //队尾指针
    }QUEUE; 
    
    //初始化队列Q  
    void InitQueue(QUEUE *Q)
    {
        Q->front=(NODE*)malloc(sizeof(NODE));
        if (Q->front==NULL) exit(0);
        Q->rear=Q->front;
    }
    
    //入队 
    void EnQueue(QUEUE *Q,int item)
    {
        NODE *s=(NODE*)malloc(sizeof(NODE));
        if (!s) exit(0);
        s->item=item;
        s->next=NULL;
        Q->rear->next=s;
        Q->rear=s;
    }
    
    //判断队列Q是否为空  
    int QueueEmpty(QUEUE Q)
    {
        if (Q.front==Q.rear) return 1;
        else return 0;
    }
    
    //获取队头元素内容  
    void  GetFront(QUEUE Q,int *item) 
    {
        if (QueueEmpty(Q)) exit(0);
        else *item=Q.front->next->item;
    }
    
    //出队 
    void DeQueue(QUEUE *Q,int *item)
    {
        if (QueueEmpty(*Q)) exit(0);
        else 
        {
            *item=Q->front->next->item;   
            NODE *s=Q->front->next;
            Q->front->next=s->next;
            free(s);
        }
    }
  • 相关阅读:
    VirtualApp
    python安装包遇到问题解决
    NMS_非极大值抑制的作用
    解释残差结构的有效性
    使用tcpdump命令抓取sql
    linux进程绑定cpu内核
    查询表空间占用情况
    数据库表分区
    Windows下如何使用ab命令做并发测试
    TCP协议
  • 原文地址:https://www.cnblogs.com/hnhcc39/p/2923631.html
Copyright © 2011-2022 走看看