Page 149 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 149

Fundamentals of Data Structures




                    Notes           printf(“Enter one of the following options:\n”);
                                    printf(“PUSH 1\n POP 2\n SHOW ELEMENTS 3\n EXIT 4\n”);
                                    scanf(“%d”, &choice);
                                    if (choice==1)
                                    {
                                    push(); menu();
                                    }
                                    if (choice==2)
                                    {
                                    pop();menu();
                                   }
                                    if (choice==3)
                                    {
                                    showelements(); menu();
                                    }
                                    }
                                   void push()
                                   {
                                    if (top<=9)
                                    {
                                    printf(“Enter the element to be pushed to stack:\n”);
                                    scanf(“%d”, &element);
                                    stack[top]=element;
                                    ++top;
                                    }
                                    else
                                    {
                                    printf(“Stack is full\n”);
                                    }
                                    return;
                                   }
                                   void pop()
                                   {
                                    if (top>0)
                                    {
                                    —top;
                                    element = stack[top];
                                    printf(“Popped element:%d\n”, element);
                                    }
                                    else
                                    {






          142                               LOVELY PROFESSIONAL UNIVERSITY
   144   145   146   147   148   149   150   151   152   153   154