Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream.h> #include<conio.h> #include<stdlib.h> Class stack { int stc

ID: 659497 • Letter: #

Question

#include <iostream.h>

#include<conio.h>

#include<stdlib.h>

Class stack

{

            int stck[6],i,n;

            int top;

            public:

                        stack()

                        {

                                    top = -1;

}

                        void push(int x)

                        {

                                    if(top>5)

                                    {

                                                cout << stack over flow;

                                                return;

}

stk[++top] = x;

cout << inserted: << x;

}

void pop()

{

            if(top < 0)

            {

            cout << stack underflow;

            return;

}

cout << deleted: << stk[top--]

}

void disply()

{

            if(top < 0)

            {

                        cout << stack empty;

                        return;

}

for(int i = top; i > 0; i--)

cout << stk[i] << ;

}

void space()

{

            for(i = 0; i<n; i++)

            while(stk[i]! =i) // swap element stk[i] with st[stk[i]]

            DSutil.swap(st, i, stk[i]);

}

};

int main()

{

            int ch, i, n;

            stack st;

            clrsr();

            while (1) // check user input

                        {

                                    cout << 1. Push 2. Pop 3. Display 4. Exit Enter your choice:;

            cin >> ch;

            switch(ch)

            {

                        case 1: cout << Enter element;

                                    cin >> ch;

                                    st.push(ch);

                                    break;

                        case 2: st.pop(); break;

                        case 3: st.display(); break;

                        case 4: exit(0);

}

getch(); // returns character read from keyboard

}

}

In addition to what is specified in the question, carefully analyze the running

time and space used by your implementation of the priority queue.

Explanation / Answer

The following fumction is specified additionally.

nt main()

{

            int ch, i, n;

            stack st;

            clrsr();

            while (1) // check user input