Answered Questions

  • What are the various kinds of sorting techniques? Which is has least worst case?

    These are some sorting techs,bubble sortquick sortinsertion sortselection sortmerge sortheap sorttell me any more sorting is found..... ad which is best....

    akshay

    • Aug 25th, 2011

    BUBBLE SORT:

    Code
    1. BUBBLE SORT:
    2. #include<iostream.h>
    3. #include<string.h>
    4. #include<math.h>
    5. #include<stdlib.h>
    6. void main()
    7. {
    8.         int a[10],n,temp;
    9.         cout<<"Enter number of elements:";
    10.         cin>>n;
    11.         cout<<"Enter no's: "<<endl;
    12.         for(int i=0;i<n;i++)
    13.         {
    14.             cin>>a[i];
    15.         }
    16.         cout<<"Sorted list is:";
    17.         for(int m=0;m<n-1;m++)
    18.         {
    19.                 for(int p=m+1;p<n;p++)
    20.                 {
    21.                         if(a[p]<a[m])
    22.                         {
    23.                           temp=a[p];
    24.                           a[p]=a[m];
    25.                           a[m]=temp;
    26.                         }
    27.  
    28.                 }
    29.  
    30.  
    31.         }
    32.         for(int x=0;x<n;x++)
    33.         {
    34.                 cout<<a[x]<<endl;
    35.         }
    36.  
    37. }
    38.