博客作业03--栈和队列

1.学习总结

2.PTA实验作业

2.1 题目1:7-1 jmu-字符串是否对称

2.2 设计思路

* 定义一个栈s用来存放str字符串的值
* str的值依次如s栈中
* str的值与s值依次比较
  如果有一个不等,return 0
  反之都相等 ,return 1

2.3 代码截图

2.4 PTA提交列表说明。

  • 主函数没有写入。

2.1 题目17-1 jmu-报数游戏

2.2 设计思路

* 创建队列q1
* 将1至n的数字依次入队列
* 如果m大于n ,return error
  否则
       while(i<n)
       如果j小于m(j自增)
       e等于队列头,消除队列头,将e插入队尾
       否则
            输出队列头,消除队列头(考虑i为1,输出的格式)

2.3 代码截图

2.4 PTA提交列表说明。


没有考虑到结尾不能有多余空格

2.1 题目1:7-2 银行业务队列简单模拟

2.2 设计思路

* 将认识排号为奇数存入队列A,反之存入B
* whileA,B都不空
 输出A队列的前两个 ,输出B队列t头
*  whileA不空
   输出A
* whileB不空
  输出B

2.3 代码截图

2.4 PTA提交列表说明


没有考虑到最小N的情况

3.截图本周题目集的PTA最后排名

3.1 栈PTA排名

3.2 队列PTA排名

3.3 我的总分

80+75=155

4. 阅读代码

#include<iostream>
using namespace std;
#define MAXSIZE 1000
typedef int QElemType;
typedef struct
{
    QElemType *base;
    int front;
    int rear;
}SqQueue;
void InitQueue(SqQueue &Q)
{
    Q.base=new QElemType[MAXSIZE];
    Q.front=Q.rear=0;
}
void CreateSqQueue(SqQueue &Q1,SqQueue &Q2,int sum)
{
    int a;
    for(int i=0;i<sum;i++)
    {
        cin>>a;
        if(a%2)
        {
            Q1.base[Q1.rear]=a;
            Q1.rear=(Q1.rear+1)%MAXSIZE;
        }
        else
        {
            Q2.base[Q2.rear]=a;
            Q2.rear=(Q2.rear+1)%MAXSIZE;
        }
    }
}
void PrintfSqQueue(SqQueue &Q1,SqQueue &Q2,SqQueue Q3,int s)
{
    int a=1;
    while((Q1.front!=Q1.rear)||(Q2.front!=Q2.rear))
    {
        if((a==1)||(a==2))
        {
            if(Q1.front!=Q1.rear)
            {
                Q3.base[Q3.rear]=Q1.base[Q1.front];
                Q3.rear=(Q3.rear+1)%MAXSIZE;
                Q1.front=(Q1.front+1)%MAXSIZE;
            }
        }
        else
        {
            if(Q2.front!=Q2.rear)
            {
                Q3.base[Q3.rear]=Q2.base[Q2.front];
                Q3.rear=(Q3.rear+1)%MAXSIZE;
                Q2.front=(Q2.front+1)%MAXSIZE;
            }
        }
        a++;
        if(a>3)
            a=1;
    }
    cout<<Q3.base[Q3.front];
    Q3.front=(Q3.front+1)%MAXSIZE;
    for(int i=0;i<s-1;i++)
    {
        cout<<" "<<Q3.base[Q3.front];
        Q3.front=(Q3.front+1)%MAXSIZE;
    }
}
int main ()
{
    int sum;
    SqQueue Q1,Q2,Q3;
    InitQueue(Q1);
    InitQueue(Q2);
    InitQueue(Q3);
    cin>>sum;
    if(sum)
    {
        CreateSqQueue(Q1,Q2,sum);
        PrintfSqQueue(Q1,Q2,Q3,sum);
    }
    else
        cout<<"0"<<endl;
    return 0;
}

代码简单的银行业务队列简单模拟。
地址:http://yuncode.net/code/c_59cdf8b5aa5d478

5. 代码Git提交记录截图

posted @ 2018-04-14 22:02  君甚秀  阅读(258)  评论(2编辑  收藏  举报