zoukankan      html  css  js  c++  java
  • 队列的基础操作

    队列是一种特殊的线性表,只允许在表的前端进行删除操作,而在表的后端进行插入操作,和栈一样,队列是一种操作受限制的线性表。进行插入操作的端称为队尾,进行删除操作的端称为队头。

    #define SIZE 5
    typedef struct queue
    {
        int inner;
    }Queue;
    Queue a[SIZE];
    Queue *head = NULL;
    Queue *tail = NULL;
    
    
    /*(1)初始化队列:Init_Queue(Queue *q) ,初始条件:队q 不存在。操作结果:构造了一个空队;
    (2)入队操作: In_Queue(Queue *q, int x),初始条件: 队q 存在。操作结果: 对已存在的队列q,插入一个元素x 到队尾,队发生变化;
    (3)出队操作: Out_Queue(Queue *q),初始条件: 队q 存在且非空,操作结果: 删除队首元素,并返回其值,队发生变化;
    (4)读队头元素:Pop_Queue(Queue *q),初始条件: 队q 存在且非空,操作结果: 读队头元素,并返回其值,队不变;
    (5)判队空操作:Empty_Queue(q),初始条件: 队q 存在,操作结果: 若q 为空队则返回为1,否则返回为0。*/
    
    
    void Init_Queue(Queue *q)
    {
        head = q;
        tail = q;
    }
    
    void In_Queue(Queue *q, int x)
    {
        if (q != NULL)
        {
            if (tail == &a[SIZE])
            {
                printf("The Queue is full filled.");
            }
            else
            {
                tail->inner = x;
                tail++;
            }
        }
    }
    
    int Out_Queue(Queue *q)
    {
        int temp = 0;
        if (head!=tail&&q!=NULL)
        {
            temp = head->inner;
            head++;
        }
        else
        {
            printf("NULL");
        }
        return temp;
    }
    
    int  Pop_Queue(Queue *q)
    {
        if (head != tail&&q != NULL)
        {
            return head->inner;
        }
        else
            printf("NULL");
    }
    
    
    int Empty_Queue(Queue *q)
    {
        if (head == tail)
            return 1;
        else
            return 0;
    }
    
    
    
    (。・∀・)ノ
  • 相关阅读:
    国际标准:ISO 8601
    Python中文问题SyntaxError
    主人与狗
    三星Galaxy note I9220 N7000 刷机ROOT工具及ROM下载
    电子书下载:Pro ASP.NET 4 in C# 2010
    Rad Studio IDE 代码编辑器增强工具 RADSplit
    电子书下载:Essential Windows Phone 7.5
    3D成像法:抖动
    减小delphi生成EXE文件体积的方法
    unisynedit 在Delphi 2010下的编译问题
  • 原文地址:https://www.cnblogs.com/FlyerBird/p/9052584.html
Copyright © 2011-2022 走看看