-1

キューを使用して値をスタックにプッシュしようとしていますが、スタックからポップを取得していません (出力なし)。これが私がやったことです:

#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#define MAX 180
#define TRUE 1
#define FALSE 0


struct cakes {
int spongecake;
int meringue;
int chocalate;
int red_velvet;
struct cakes *next;
};

struct stack{

    int top;

    int cake[10];
};

struct Queue{
   int front;
   int rear;
   int count;
   int cake[10];

    };



void conveyer_order(struct cakes *);
void baking_order(struct cakes *);


int isFull(struct stack *);
int isEmpty(struct stack *);
void push(struct stack *,int);
int pop(struct stack *);


void init(struct Queue *);
int isqueueFull(struct Queue*);
void insert(struct Queue*,int);
int isqueueEmpty(struct Queue *);
int removes(struct Queue *);



main()
{
struct cakes *head;
head=(struct cakes *)malloc(sizeof(struct cakes));
conveyer_order(head);   

head->next=(struct cakes *)malloc(sizeof(struct cakes));
baking_order(head->next);

}


int isFull(struct stack *k)
{
    if(k->top==10-1)
    {
        return TRUE;
    }
    else 
    {

       return FALSE;
    }
}

int isEmpty(struct stack *k)
{
    if(k->top==-1)
    {
        return TRUE;

    }
    else
    {

        return FALSE;
    }

}

int pop(struct stack *sptr)
{
   int ret=NULL;
   if(!isEmpty(sptr))
    {
        ret=sptr->cake[sptr->top];
        sptr->top--;
        return ret;
    }
}

void push(struct stack *sptr,int x)
{
    if(!isFull(sptr))
    {
        sptr->top++;
        sptr->cake[sptr->top]=x;
    }
}   



void init(struct Queue *q)
{
    q->front=0;
    q->rear=10-1;
    q->count=0;


}

int isqueueFull(struct Queue *q)
{
    if(q->count==10)
    {
        return 1;
    }
    else 
    {

        return 0;
    }
}



void insert(struct Queue *q,int x)
{
    if(!isqueueFull(q))
    {
        q->rear=(q->rear+1)%10;
        q->cake[q->rear]=x;
        q->count++;

    }

}

int isqueueEmpty(struct Queue *q)
{
    if(q->count==0)
   {
       return 1;

    }
    else
    {

     return 0;
    }

}


int removes(struct Queue *q)
{
   int cakeempty=NULL;

   if(!isqueueEmpty(q))
   {
        cakeempty=q->cake[q->front];
        q->front=(q->front+1)%10;
        q->count--;
        return cakeempty;
   }

}


void baking_order(struct cakes *theorder)
{
int v=0;

struct stack baking;
struct Queue belt;

baking.top=-1;
int value1=0;
int value2=0;
 theorder->spongecake=20;
 theorder->chocalate=40;
 theorder->red_velvet=30;
 theorder->meringue=75;     

init(&belt);

while(!isqueueFull(&belt))
{
    insert(&belt,theorder->meringue);
    insert(&belt,theorder->chocalate);
    insert(&belt,theorder->red_velvet);
    insert(&belt,(theorder->spongecake));
}



value1=removes(&belt);

while(!isqueueEmpty(&belt))       

{

while(!isFull(&baking))
{

value2=removes(&belt);




    if(value1>=value2)
    {


            push(&baking,value2);
        value1=value2;

}
    else
    {
    insert(&belt,value2);
    }
}
}


while(!isEmpty(&baking))
{
    printf("\n%d",pop(&baking));
}   
}

スタックに渡さずに値を出力しようとしましたが、動作します。問題は 2 つの while ループにあると思います。

このエラーを修正するにはどうすればよいですか?

お時間をいただきありがとうございます。

4

1 に答える 1