zoukankan      html  css  js  c++  java
  • 数据结构之顺序队列-初始化,入栈,出栈

    #include<stdio.h>
    #include<iostream>
    #include<malloc.h>
    #include<stdlib.h>
    #include<string.h>
    using namespace std;
    #define maxsize 60
    typedef struct node
    {
    int data[maxsize];
    int front;
    int rear;
    }seq;
    void init(seq *q)
    {
    q->front=0;
    q->rear=0;
    }
    int empty(seq q)
    {
    if(q.front==q.rear)
    return 1;
    else
    return 0;
    }
    int insert(seq *q,int e)
    {
    if(q->rear==maxsize)
    return 0;
    q->data[q->rear]=e;
    q->rear=q->rear+1;
    return 1;
    }
    int del(seq *q,int *e)
    {
    if(q->front==q->rear)
    return 0;
    else
    {
    *e=q->data[q->front];
    q->front=q->front+1;
    return 1;
    }
    }

    int main()
    {
    seq q;
    int str[]={1,2,3,4,5,6,7,8,9};
    int i,length=9;
    int x;
    init(&q);
    for(int i=0;i<length;i++)
    {
    insert(&q,str[i]);
    }
    del(&q,&x);
    cout<<"队列首元素为:"<<x<<endl;
    printf("剩余队列元素为:");
    if(!empty(q))
    {
    for(i=q.front;i<q.rear;i++)
    {
    cout<<q.data[i]<<" ";
    }
    }
    }

  • 相关阅读:
    SpringBoot整合阿里云OSS
    UVALive
    HDU 5794 A Simple Chess dp+Lucas
    数论
    UVALive
    UVALive
    HDU 5792 World is Exploding 树状数组+枚举
    UVALive
    UVALive
    UVALive
  • 原文地址:https://www.cnblogs.com/mykonons/p/6611154.html
Copyright © 2011-2022 走看看