Page 152 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 152

Unit 9: Stacks




           return;                                                                              Notes
           }
           else
           {
           while(temp!=NULL)
           {
           printf(“\n%d”,temp->data); /* display all the values of the stack*/
           temp=temp->next;     /*  from the front node to the last node*/
           }
           }
           }     /*end of function display*/
          /* Definition of main function */
          void main()
          {
           int item, ch;
           char choice=‘y’;
           node *p=NULL;
           do
           {
           clrscr();
           printf(“\t\t\t\t*****MENU*****”);
          printf(“\n\t\t\t1. To PUSH an element”);
           printf(“\n\t\t\t2. To POP an element”);
           printf(“\n\t\t\t3. To DISPLAY the elements of stack”);
           printf(“\n\t\t\t4. Exit”);
           printf(“\n\n\n\t\t\tEnter your choice:-”);
           scanf(“%d”,&ch);
           switch(ch)
           {
           case 1:
           printf(“\n Enter an element which you want to push “);
           scanf(“%d”,&item);
           push(&p,item);
           break;
           case 2:
           item=pop(&p);
           if(item!=NULL);
           printf(“\n Detected item is %d”,item);
           break;
           case 3:
           printf(“\nThe elements of stack are”);






                                           LOVELY PROFESSIONAL UNIVERSITY                                   145
   147   148   149   150   151   152   153   154   155   156   157