69,382
社区成员
发帖
与我相关
我的任务
分享
int IsStackEmpty(Sgoods *S)
{
return(S->top==-1? 1:0);
}
int IsStackFull(Sgoods *S)
{
return(S->top==MAXSIZE-1? 1:0);
}
while (!IsStackEmpty(S))
{
PopStack(S,&x);
PushStack(B,x) ;
}
#include "stdio.h"
#include "malloc.h"
#define maxsize 50
typedef struct
{
long date[maxsize];
int top;
}Sgoods;
typedef struct
{
long date[maxsize];
int rear;
int front;
}Qgoods;
/*****init*******/
void InitStack(Sgoods *S)
{
S->top=-1;
}
void InitQueue(Qgoods *Q)
{
Q->rear=0;
Q->front=0;
}
/***********Stack*********/
int IsStackEmpty(Sgoods *S)
{
return(S->top==-1? 1:0);
}
int IsStackFull(Sgoods *S)
{
return(S->top==maxsize-1? 1:0);
}
int PushStack(Sgoods *S,long x)
{
if(IsStackFull(S))
return 0;
S->top++;
S->date[S->top]=x;
return 1;
}
int PopStack(Sgoods *S, long *x)
{
if(IsStackEmpty(S))
return 0;
*x=S->date[S->top];
S->top--;
return 1;
}
int GetTop (Sgoods *S, long *x)
{
if (S->top == -1)
return 0;
else
{
*x=S->date[S->top];
return 1;
}
}
void
/*************queue*********/
int IsQueueFull (Qgoods *Q)
{
return(Q->rear-Q->front==maxsize? 1:0);
}
int IsQueueEmpty (Qgoods *Q)
{
return(Q->front==Q->rear? 1:0);
}
int EnterQueue(Qgoods *Q,long x)
{
if(IsQueueFull(Q))
return 0;
Q->date[Q->rear]=x;
Q->rear++;
return 1;
}
int DeleteQueue(Qgoods *Q,long *x)
{
if(IsQueueEmpty(Q))
return 0;
*x=Q->date[Q->front];
Q->front++;
return 1;
}
void JinHuo (Qgoods *Q)
{
while (1)
{
long d=0;
int t=0;
printf("please input the date in produced(as:20100925):\n ");
scanf("%ld",&d);
printf("please input the products' quantity:\n");
scanf("%t",&t);
while (t!=0)
{
EnterQueue(Q, d) ;
t--;
}
printf("JinHuo.......OK\n");
printf("Continue to JinHuo?(Y/N)\n");
if (getchar()=='Y');
else return;
}
}
void ShangJia (Sgoods *S ,Qgoods *Q)
{
long x,y,a;
Sgoods *B=(Sgoods *)malloc(sizeof(Sgoods))
while (!IsStackEmpty(S))
{
PopStack(S,&x);
PushStack(B,x) ;
}
while(!IsQueueEmpty(Q) && !IsStackFull(S))
{
DeleteQueue(Q,&y) ;
PushStack(S,y) ;
}
printf ("ShangJia..........OK\n");
}
void ShouHuo (Sgoods *S)
{
int k,temp;
long a[maxsize];
printf("How many goodses will you like to buy?\n");
scanf("%d",&k);
temp=k;
for (;k>0;k--)
PopStack(S,&a[temp-(k-1)]);
printf("You have buy %d goodses\n",k);
}
void menu(char **menu,int n);
void main()
{
Sgoods *S=(Sgoods *)malloc(sizeof(Sgoods));
// Sgoods *B=(Sgoods *)malloc(sizeof(Sgoods));
Qgoods *Q=(Qgoods *)malloc(sizeof(Qgoods));
int choose=1;
// char *k=" ",
char *s="\n *";
char *xs="**********************************";
while(choose)
{
char *menu1[]={"***************MENU",
"1->JinHuo\n",
"2->ShangJia\n ",
"3->ShouHuo\n",
"0->exit\n"};
menu(menu1,4);
scanf("%d",&choose);
switch(choose)
{
case 1: JinHuo(Q); break;
case 2: ShangJia(S,Q); break;
case 3: ShouHuo(S); break;
case 0: break;
}
getchar();
printf("%s%s******%s*",s,xs,xs);
}
}