Saturday, July 30, 2011

Various Sorting Techniques used to sort the Elements of an Array:Bubble Sort-Selection Sort -Insertion Sort-Quick Sort-Merge Sort-Heap Sort


Various Sorting techniques can be implemented to sort an Integer array .Some of them are
  • Bubble Sort
  • Selection Sort
  • Insertion Sort 
  • Quick Sort
  • Merge Sort
  • Heap Sort


Bubble Sort:

Bubble Sorting is the Most Basic Sorting technique.The various steps in technique

1. Compare the two  adjacent elements of the array
2. Check if one on the one on the left is large than one on the right, swap them.
3. Move to the right by one position.

The Code used for Implementing Bubble Sort is given Below
--------------------------------------------------------------

void sort() 
{
int x=l;
int y=0;
int a,b=0;
for (int rep=0;rep<l*4;rep++)
{
for(int i=0;i<x-1;i++)
{
a=ar[i];
b=ar[i+1];
if(a>b)
{

y=a;
a=b;
b=y;
ar[i]=a;
ar[i+1]=b;
}
}
}
}


----------------------------------------------------------------
Other Sorting Techniques will discussed in the future posts.

2 comments:

  • sudheer says:
    January 13, 2012 at 8:33 PM

    good site helpful to students,my request is to post as many programes as possible .thank you..

  • Techman says:
    January 13, 2012 at 8:44 PM

    Thank you sudheer.Please do join the blog.

Post a Comment

Subscribe

The Source Codes Published in this Blog can be used freely for Educational purposes but should not be reproduced on any other Blog or Website without the consent of the author.