//商品货架管理系统,这个是自己刚学完数据结构写的书的一个实验,写的很多,不够简洁,
//其实里面也没什么东西,优先级队列之类的也没有用着,就是拿队列进行了个存储和排序
//不过是自己初学写出来的,鼓励下自己。O(∩_∩)O~拿来在大家面前献丑了。
//各位大哥大姐可以指教,留言本人百度 ID,或者发邮件至:hsustar@foxmail.com,共同交
//流讨论,共同进步。PS:本人就学于东秦,若能给本校学子们提供帮助,实属莫大荣幸。
//不过高手也不要笑话咱啊。嘿嘿,进入主题吧。
//头文件
struct Queue{
//定义一个队列
int*Qlist;
int maxsize;
int rear,front;
};
void InitQueue(Queue&QL,const int ms);
void ClearQueue(Queue&QL);
int QueueEmpty(Queue&QL);
int QueueFull(Queue&QL);
bool InsertQueue(Queue&QL,const int &item);
void OrderQueue(Queue&QL);
int DeQueue(Queue&QL);
struct stack{
int* Slist;
int top;
int Maxsize;
};
void Initstack(stack&SL,const int MS);
bool Stackempty(stack&SL);
bool Stackfull(stack&SL);
void Clearstack(stack&SL);
int Push(stack&SL, int&item);
int Pop(stack&SL);
void Traverstack(stack&SL);
----------------------------------
//实现文件
#include
#include
#include "sy3.h"
void InitQueue(Queue&QL, const int ms)
{
QL.Qlist=new int [ms];
if(!QL.Qlist)
{
cerr<<"给队列分配内存失败。"<}
QL.rear=0; QL.front=0; QL.maxsize=ms;
}
void ClearQueue(Queue&QL) {QL.front=QL.rear=0; }
int QueueEmpty(Queue&QL) {return QL.rear==QL.front; }
int QueueFull(Queue&QL)
bool InsertQueue(Queue&QL,const int&item)
{
{return (QL.rear+1)%QL.maxsize==QL.front; } //判满
//各项值,初始化
//清空队列
//判空
//插入元素进队
//尾指针不能超过 maxsize
//大小顺序排队
//出队
if(QueueFull(QL))
{
cerr<<"Queue is full"<
{
cout<<"Queue is empty"<
#include
//栈的初始化
//判空
//判满
//清空栈
//元素进栈
//元素出栈
//输出栈
#include "sy3.h"
const int M=11;
const int N=10;
void main(){
cout<<"---------------商品货架管理----------------"<
>x;
if(x>20100101&&x<20101124)
InsertQueue(q,x);
else {cout<<"日期不合理。请重新输入:"<>x;}
}
OrderQueue(q);
temp=q.Qlist[0];
stack s;
Initstack(s,N);
for(i=0;i<10;i++)
{
x=DeQueue(q);
Push(s,x);
//将输入的日期排队
//存储最大(近)的日期
//栈初始化
/将排序后的队列推进栈
}
cout<<"商品已经按照日期从近到远的时间顺序放入货架。从底部到顶部的顺序为:
"<>x;
while(x<0&&x>10)
{
cout<<"要求的商品数量不合理,请重新输入:"<>x;
//从底到顶,显示栈元素
}
for(i=0;i{
x=Pop(s);
InsertQueue(q,x);
}
t=q.maxsize-q.rear-1;
cout<<"现在货架还能放下"<
>x;
if(x>temp&&x<20101124)
InsertQueue(q,x);
else
{
}
cout<<"商品时间太旧,请重新输入:"<>x;
}
OrderQueue(q);
for(i=0;i最后部分有三行没有显示完全,在后面的图片里有补全,可以对比下补上。