堆叠:按下然后弹出并再次推送到其他堆叠器

时间:2014-02-12 12:18:45

标签: c stack

我有一个“卡车”和一个“堆叠器”都使用堆栈。用户能够分配卡车的大小(我使用过malloc),堆叠器大小是固定大小的5。 我能够将价值推向卡车,但如何将卡车的顶部弹出并将其推入堆垛机?

struct box
{
    int item;
    int bin;
    int top;
}*boxs,*stacker;

int i;
int num;
int topt = -1;
int tops = -1;

void main()
{
    void truck();
    void display();
    int op;//option
    char ch;//choice

    do{
        system("cls");
        printf("\n Stack:-");
        printf("\n\n 1.<Insert>");
        printf("\n 2.<Display>");
        printf("\n\n Option: ");

        scanf("%d", &op);fflush(stdin);

        switch(op)
        {
            case 1:truck();break;
            case 2:display();break;
            default:printf("\n Invalid Choice!!!");break;

        } printf("\n\n\n Continue?(Y/N): ");

        scanf("%c", &ch);    fflush(stdin);
    }while(ch=='y' || ch=='Y');
    return;
}

void truck()
{
    struct box e;
    int a,temp;


    printf("Enter Number of Boxes to unload from the Truck: ");
    scanf("%d", &num);
    boxs= (struct box*)malloc(sizeof (struct box));
    temp=num;
    /*tempt->tops=copy-1;*/

    for(a=0; a<num;a++)
    {
        topt++;
        temp--;
        /*tempt[copy-a].tops--;*/
        printf("\n1. Enter Item ID: ");
        scanf("%d", &e.item);
        boxs[a].item=e.item;fflush(stdin);
        /*tempt[copy-a].item=e.item;*/


        printf("\n2. Enter Bin ID: ");
        scanf("%d", &e.bin);
        boxs[a].bin=e.bin;fflush(stdin);
        //tempt[copy-a].bin=e.bin;
    }
    stackers();
}

void display()
{
    for(i=0;i<=topt;i++)
    {
        printf("\n%d",boxs[i].item);
        printf("\n%d",boxs[i].bin);
    }
}


void stackers()
{
}

0 个答案:

没有答案