Selection sort, Bubble Sort and Insertion sorting on C/C++

if you guys are familier to array in C, then you can understand what is selction, bubble and insertion sorting is.
these snippet below will work only for 5 numbers.


Selection sorting




Bubble Sorting
main()
{
int num[5]={5,2,4,1,3};
int c,d,t;
clrscr();
for(c=0;c<4;c++)
{
  for(d=c+1;d<5;d++)
  {
   if(num[c]>num[d])
   {
    t=num[c];
    num[c]=num[d];
    num[d]=t;
   }

  }
}
for(c=0;c<5;++c)
printf("%d",num[c]);
getch();
}


Insertion sorting

0 comments:

Post a Comment

 

Copyright © 2011 Mbojo4Lab | Design by Kenga Ads-template