Page 151 - DCAP407_DATA_STRUCTURE
P. 151

Data Structure



                                              if ( F == NULL || el_pri < F->PRI )
                                          {
                                              new->next = F;
                                              F = new;
                                          }
                                              else
                                          {
                                              q = F;
                                              while ( q->next != NULL && q->next->PRI <= el_pri )
                                              q = q->next;
                                              new->next = q->next;
                                              q->next = new;
                                              }
                                          }
                                          void del()
                                          {
                                              if ( F == NULL )
                                              {
                                                printf( "\n QUEUE UNDERFLOW\n" );
                                              }
                                              else
                                              {
                                                new = F;
                                                printf( "\nDeleted number is %d\n", new->value );
                                                F = F->next;
                                                free( F );
                                              }
                                          }
                                          void disp()
                                          {
                                              tmp = F;
                                              if ( F == NULL )
                                                  printf( "QUEUE IS EMPTY\n" );
                                              else
                                              {
                                              printf( "QUEUE IS:\n" );
                                              while ( tmp != NULL )
                                              {
                                               printf( "\n%d[PRI=%d]", tmp->value, tmp->PRI );
                                               tmp = tmp->next;
                                               }
                                              }
                                          }
                                          int main()
                                          {
                                              int choice;
                                              clrscr();
                                              while(1)
                                              {
                                             printf( "\n 1. INSERT \n 2. DELETE \n 3. DISPLAY \n 4. EXIT" );
                                             printf( "\n Enter your choice" );
                                             scanf( "%d", &choice );
                                             switch ( choice )
                                             {
                                               case 1:
                                                  ins();
                                                 break;




                          144                     LOVELY PROFESSIONAL UNIVERSITY
   146   147   148   149   150   151   152   153   154   155   156