Program 1: Write A Programto Implement Bubble Sort. Source Code
Program 1: Write A Programto Implement Bubble Sort. Source Code
Program 1: Write A Programto Implement Bubble Sort. Source Code
Source Code:
#include<iostream>
using namespace std;
int main()
{
int a[10],i,j,t;
for(i=0;i<10;i++)
{
cout<<" \nEnter number "<<i<<" : ";
cin>>a[i];
}
for(i=9;i>=0;i--)
{
for(j=0;j<i;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
for(i=0;i<10;i++)
{
cout<<" "<<a[i];
}
return 0;
}
Output:
int main()
{
int x,y;
cout<<"\nEnter Size of Array : ";
cin>>x;
int a[x];
for(int i=0;i<x;i++)
{
cout<<"\nENter Number : ";
cin>>a[i];
}
insertion_sort(a,x);
cout<<"\n\nImplementing Insertion Sort, Sorted array is : ";
for(int i=0;i<x;i++)
{
cout<<" "<<a[i];
}
return 0;
}
void radix_sort(int[],int);
void count_sort(int[],int,int);
int max_value(int[],int);
int main()
{
int x,y;
cout<<"\nEnter Size of Array : ";
cin>>x;
int a[x];
for(int i=0;i<x;i++)
{
cout<<"\nENter Number : ";
cin>>a[i];
}
radix_sort(a,x);
cout<<"\n\nImplementing Radix Sort, Sorted array is : ";
for(int i=0;i<x;i++)
{
cout<<" "<<a[i];
}
return 0;
}
}
return max;
}
void count_sort(int a[],int n,int pvalue)
{
int temp[n], i;
int count[10] = {0}; // acts as a bucket, to count occurence
int main()
{
int x,y,l;
cout<<"\nEnter Size of Array : ";
cin>>x;
int a[x];
for(int i=0;i<x;i++)
{
cout<<"\nENter Number : ";
cin>>a[i];
}
merge_sort(a,x);