SORTING
Sorting is a basic application in computer science.
Basically sorting means arranging some given data in a given sequence. The
way of arranging may be in increasing or decreasing order.
Suppose an Array value contains 10 elements as follows:
VALUE: 7, 9, 11,
5, 4, 99
After sorting, VALUE must be like
VALUE: 4, 5, 7, 9,
11, 99
The different methods of sorting are
1.
BUBBLE SORT
2.
SELECTION SORT
3.
INSERTION SORT
4.
QUICK SORT
5.
MERGE SORT
6.
HEAP SORT
Here we will make some C-CODES on
these techniques
1. BUBBLE SORT
Code for bubble sort………(I have used dev-cpp software for coding)
#include<stdio.h>
int main()
{
int i,j,n,a[200],temp;
printf("Enter how much
data do u want??\n");
scanf("%d",&n);
printf("Put the numbers
are in unsorted oriented\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
//##############################################################################################################
//unsorted array
printf("The Inputed array::\n");
for(i=0;i<n;i++)
{
printf("%d
",a[i]);
}
//##############################################################################################################
//block for sorting
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("\n\nThe Sorted array is::\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
getch();
return 0;
}
OUTPUT:
No comments:
Post a Comment