Answers for "Test the program using the following procedure: STACK of size N=6 1. Call PUSH(5) 2. Call PUSH(2) 3. Call PUSH(3) 4. Call POP() 5. Call PUSH(6) 6. Call PUSH(9) 7. Call PUSH(3) 8. Call DISPLAY() 9. Call TOP()"

0

Test the program using the following procedure: STACK of size N=6 1. Call PUSH(5) 2. Call PUSH(2) 3. Call PUSH(3) 4. Call POP() 5. Call PUSH(6) 6. Call PUSH(9) 7. Call PUSH(3) 8. Call DISPLAY() 9. Call TOP()

#include <iostream>

using namespace std;

int top = 1;
int arr[5];

void push(int arr[], int item)
{

    if (top > 5)
    {
        cout << "Stack is Over Flow";
    }
    else
    {
        top = top + 1;
        arr[top] = item;
    }

    return;
}

void pop(int arr[])
{

    for (int a = 0; a < 1; a++)
    {
        if (top == 0)
        {
            cout << "Stack Is Uder Flow";
            break;
        }

        else
        {

            arr[top] = arr[top + 1];
            top = top - 1;
        }
    }

    return;
}

void peak(int arr[], const int size)
{

    cout << endl
         << "Your Stack Value IS" << endl;
    for (int o = size; o > 0; o--)
    {
        if (arr[o] != 0)
        {
            cout << arr[o] << endl;
        }
    }
}

int _tmain(int argc)
{
    system("color f0");
    push(arr, 5);
    push(arr, 2);
    push(arr, 3);
    int a = arr[4];
    int b = arr[3];
    pop(arr);
    pop(arr);
    push(arr, b + 2);
    push(arr, 8);
    push(arr, a + b);
    cout << " Yor Stack Value IS" << endl;
    while (top != 0)
    {
        if (arr[top] != 0)
        {
            cout << " " << arr[top] << endl;
        }
        pop(arr);
    }

    return 0;
}
Posted by: Guest on April-21-2021

Browse Popular Code Answers by Language