数据结构-队列-队列的输入输出操作

Description
建立队列的顺序存储结构,进行入队和出队的操作,并输出队列中的数据元素。
 
Input
多组输入,每组输入为两行,第一行输入一个整数,为输入数据的个数,第二行输入要输入的数据(整数).
 
Output
每行输出是队列里面的数据元素。注意:最后一个输出时后面没有空格!!!
Sample Input
5
1 2 3 4 5
3
12 3 90
 
Sample Output
1 2 3 4 5
12 3 90
#include<iostream>
#include<stdio.h>
#define MaxQsize 105
using namespace std;

typedef struct{//队列定义
    int *base;//表示数据类型
    int front;
    int rear;
}SqQueue;

void initQ(SqQueue &Q){//初始化
    Q.base=new int[MaxQsize];
    Q.front=Q.rear=0;
}

void creatQ(SqQueue &Q,int len){//创建
    for(int i=0;i<len;i++){
        cin>>Q.base[Q.rear];
        Q.rear++;
    }
}
void Print(SqQueue Q,int len){//输出
    for(int i=0;i<len;i++){
        cout<<Q.base[Q.front];
        Q.front++;
        if(i!=len-1){
            cout<<" ";
        }
    }
    cout<<"\n";
}

int main(){
    SqQueue Q1;
    int len;
    while(cin>>len){
        initQ(Q1);
        creatQ(Q1,len);
        Print(Q1,len);
    }
    return 0;
}

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值