SORTING METHODS IN C PROGRAMMING
Dr RAHUL DEOLE -Computer/IT Expert -Tata Consulting Engineers Ltd
email-
[email protected] Sorting techniques-:? To Arrange the element list in ascending /descending order is called as sorting Techniques?
TYPES OF SORTING
1) BUBBLE SORTING TECHINQUES
2) INSERTION SORTING TECHINQUES
3) SELECTION SORTING TECHINQUES
4) QUICK SORTING TECHNIQUES
5) MERGE SORTING TECHINQUES
6) HEAP SORTING TECHINQUES
7) SHELL SORTING TECHNINQUES
1) Bubble sorting techniques
-? In this method basic idea is to compare two adjoining values and
exchange them or swap them if they are not in proper order ,then start back at the beginning comparing &swapping if necessary continues the processes of n passess until series is a[1] ------------ a[n] is orted list"
program in ?c? is given below for bubble sorting mtehod
#include<stdio.h>
#include<conio.h>
Void main()
{ long int bubb_sort();
clrscr();
printf("\n ### BUBBLE SORTING METHOD ###\n");
bubb_sort();
getch();
}
long int bubb_sort()
{ int n,a[15],i,j,temp;
printf("\n Enter the Number of elements to be sorted \n");
scanf("%d",&n);
printf("\n ENTER THE ELEMENTS NOW\n");
for(i=0; i<=n; i++)
{ scanf("%d",&a[i]);
getch();}
for(i=0; i<=n; i++)
{
for(j=i+1; j<=n; j++)
{ if (a[i] > a[j])
{ temp=a[i];
a[i]=a[j];
a[j]=temp;
}} }
printf("\n SORTED ARRAY AFTER BUBBLE SORTING \n");
for(i=0; i<=n; i++)
{ printf("\t\t %d",a[i]);
getch();}
}