Objective:
1. To understand the different sorting methods like
Bubble, Inserion, Quick, Bucket.
2. To understand why & how to use sorting.
Problem Statement:
Write a program to implement Bubble, Insertion, Quick,
Bucket and display result.
*/
#include
#include
void bucket();
void selection();
void sort();
void insert();
void bubble();
void quicksort(int items[],int left,int right,int n);
int max;
int a[10], b[10], c[10], d[10];
int i, j, k, n, temp, ch;
void main()
{
int i=0,n,ch;
clrscr();
do
{
printf("\n\nWhich sorting you have to do?");
printf("\n1.Insertion sort\n2.Bubble sort\n3.Quick sort");
printf("\n4.Bucket sort\n5.Exit\n6.Selection Sort\nEnter:");
scanf("%d", &ch);
switch(ch)
{
case 1: //insertion sort
insert();
break;
case 2: // bubble sort
bubble();
break;
case 4:
bucket();
break;
case 5:
exit(5);
break;
case 3:
printf("\n\nEnter the size of array:");
scanf("%d",&n);
max=n;
printf("Enter Array Elements:");
for(i=0;i
if(i<=j) { temp=a[i]; a[i]=a[j]; a[j]=temp; i++; j--; } } while(i<=j); for(i=0;i
}
}
void insert()
{
printf("\n\nEnter the no of elements in array: ");
scanf("%d", &n);
printf("Enter the 1st element:");
scanf(" %d",&a[0]) ;
printf("Enter other elements:");
for(i=1; i
{
temp = a[j+1];
a[j+1] = a[j];
a[j] = temp;
}
}
}
printf("Sorted elements are :");
for(j=0; j
{
printf(" %d ",i);
freq[i]--;
}
}
void selection()
{
printf("\nEnter no. of elements:");
scanf("%d", &n);
printf("\nEnter array elements:");
for(i=0; i
k = j;
if(k != i)
{
temp = a[i];
a[i] = a[k];
a[k] = temp;
}
}
printf("Sorted elements are :");
for(j=0; j
}
No comments:
Post a Comment