Page 256 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 256

Unit 12: Sorting





             sort(a,5);                                                                         Notes
             printf(“The sorted list a is:\n”);
             dis(a,5);
             sort(b,5);
             printf(“The sorted list b is:\n”);
             dis(b,5);
             merge(a,b,c,5);
             printf(“The elements of merged list are \n”);
             dis(c,10);  /*Display the merged list*/
             getch();
          }
          void read(int c[],int i)
          {
             int j;
             for(j=0;j<i;j++)
                scanf(“%d”,&c[j]);
             fflush(stdin);
          }
          void dis(int d[],int i)
          {
             int j;
             for(j=0;j<i;j++)
                printf(“%d “,d[j]);
             printf(“\n”);
          }
          void sort(int arr[] ,int k)
          {
             int temp;
             int i,j;
             for(i=0;i<k;i++)
             {
                for(j=0;j<k-i-1;j++)
                {
                   if(arr[j]<arr[j+1])
                   {
                      temp=arr[j];
                      arr[j]=arr[j+1];
                      arr[j+1]=temp;
                   }
                }




                                           LOVELY PROFESSIONAL UNIVERSITY                                   251
   251   252   253   254   255   256   257   258   259   260   261