Page 162 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 162

Unit 9: Stacks




          Self Assessment                                                                       Notes

          Fill in the blanks:
          12.  ......................... is an algorithm that confirms that the number of closing parenthesis equals
               opening parenthesis by using stack.

          13.  All ......................... expressions cannot be evaluated by using the left to right order of the
               operators inside the expression.
          14.  Each operator in a ......................... string corresponds to the previous two operands .

          15.  The left parenthesis has the ......................... priority when it is read from the expression




             Case Study  C Program using Pointers

             Program to implement stack with its operations using pointers
             #include<stdio.h>
             #include<conio.h>
             #include<stdlib.h>
             #define MAX 50
             int size;
             /* Defining the stack structure */
             struct stack
             {
                 int arr[MAX];
                 int top;
             };
             /* Initializing the stack(i.e., top=-1) */
             void init_stk(struct stack *st)
             {
                 st->top = -1;
             }
             /* Entering the elements into stack */
             void push (struct stack *st,int num)
             {
                 if(st->top == size-1)
                     {
                     printf("nStack overflow(i.e., stack full).");
                     return;
                     }
                 st->top++;
                 st->arr[st->top] = num;
             }
                                                                                 Contd...



                                           LOVELY PROFESSIONAL UNIVERSITY                                   155
   157   158   159   160   161   162   163   164   165   166   167