-1

配列のエンキュー、デキュー、要素数のカウント、および C++ での表示を使用して、次のキュー操作を実行するメニュー駆動型プログラム用の C++ プログラムを作成する必要がありますか? これを作る方法は?私はC++が非常に苦手です.誰かが私を案内したり、助けたり、完全なプログラムにリンクして、それを研究して理解することはできますか?!!! やってみたけどできなかったので本当に助けが必要

これは正しいですか?

#include<iostream.h>
#include<conio.h>
void push(int st[],int data,int &top);      //declaring a push class
void disp(int st[],int &top);       //declaring display class
int pop(int st[],int &top);                       //declaring a pop class
int flg=0;
int top=-1,tos=-1;
int st[50];

void push(int st[],int data,int &top)          //push
{
    if(top==50-1)
    flg=0;
    else
    {
        flg=1;
        top++;
        st[top]=data;
    }
}

int pop(int st[],int &top)                      //pop
{
    int pe;
    if(top==-1)
    {
        pe=0;
        flg=0;
    }
    else
    {
        flg=1;
        pe=st[top];
        top--;
    }

    return(pe);
}

void disp(int st[],int &top)                //display
{
    int i;
    if(top==-1)
    {
        cout<<"\nStack is Empty";
    }
    else
    {
        for(i=top;i>=0;i--)
        cout<<"\t"<<st[i];
    }
}

void main()
{
    int dt,opt;                              // declare varible
    int q=0;
    clrscr();
    cout<<"\t\t\tStack operations";
    cout<<"\n\n\tMain Menu.........";
    cout<<"\n\n1.Push";
    cout<<"\n\n2.Pop";
    cout<<"\n\n3.Exit";
    cout<<"\n\n4.display";

    do                                     // useing do while for to make choice and select any options
    {
        cout<<"\n\n\tEnter Your Choice 1-4:";            //entering your choice
        cin>>opt;

        switch(opt)
        {
            case 1:
                cout<<"\nEnter the Element to be Push:";
                cin>>dt;
                push(st,dt,tos);

                if(flg==1)
                {
                    cout<<"the push is done";

                    if(tos==50-1)
                        cout<<"\nStack is Now Full";
                }
                else
                   cout<<"\nStack Overflow Insertion Not Possible";
            break;
            case 2:
                dt=pop(st,tos);
                if(flg==1)
                {
                    cout<<"\n\tData Deleted From the Stack is:"<<dt;
                    cout<<"\n \t pop is done";
                }
                else
                    cout<<"\nStack Empty,Deletio Not Possible:";
            break;
            case 3:
                q=1;
            break;
        default:
                            cout<<"\nWrong Choice Enter 1-3 Only";

        case 4:
                disp(st,tos);
        break;
        }
    } while(q!=1);
}
4

1 に答える 1