• 简单的顺序队列


    #include<stdio.h>
    #include<malloc.h>
    #define max 100
    typedef struct node
    {
    int queue[max];
    int front,rear;
    }q,*queue;
    void init(queue p)
    {
    p->front=-1;
    p->rear=-1;
    }

    int empty(queue p)
    {
    if(p->front==p->rear)
    {
    printf("队列为空 ");
    return 1;
    }
    else
    {
    return 0;
    }
    }

    int insert(queue p,int x)
    {
    if(p->rear==max)
    {
    printf("队列已满 ");
    }
    else
    {
    p->queue[p->rear++]=x;
    }
    return 1;
    }


    int del(queue p,int *n)
    {
    if(p->front==p->rear)
    {
    printf("队列已空 ");
    }
    else
    {
    *n=p->queue[p->front++];
    printf("被删除元素:%d ",*n);
    printf(" ");
    }
    return 1;
    }

    void tra(queue p)
    {
    for(int i=p->front;i<p->rear;i++)
    {
    printf("%d ",p->queue[i]);
    }
    }

    int main()
    {//动态内存,所以指针指向数组的内存没有执行立即被分配
    queue l;int n;
    l=(queue)malloc(sizeof(q));
    init(l);
    insert(l,1);
    insert(l,2);
    insert(l,3);
    insert(l,4);
    insert(l,5);
    tra(l);
    printf(" ");
    empty(l);
    del(l,&n);
    tra(l);


    }

  • 相关阅读:
    maven 手工装入本地包
    一个简单的算法--找出样本中出现次数最多的数字
    tortoise Git 访问题
    python 的数值
    python 的运算符
    python3代码运行器
    python 3.X基础
    Python 3.X和Python 2.X的区别
    文件操作
    函数讲解
  • 原文地址:https://www.cnblogs.com/mykonons/p/5870448.html
Copyright © 2020-2023  润新知