CODE For Bubble Sort
"Nice One Program"
#include<iostream.h>
#include<conio.h>
int main()
{ clrscr();
int n;
//int a[]={7,25,22,5,4,60,20,11,2,9}; //taking cont elements
int *a=NULL; //dynamic array
cout<<"enter numb of elemnt:";
cin>>n;
a=new int[n];
int temp,i,j,A,B;
cout<<"\n\nenter elements:";
for(i=0;i<n;i++)
cin>>a[i]; //Input Values
cout<<"\n\nBefore sorting";
for(i=0;i<n;i++)
cout<<a[i]<<" "; //Before
for(i=0;i<n;i++)
for(j=0;j<n-1-i;j++) //Sorting
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
cout<<endl<<"\nAfter Sorting:";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
getch();
return 0;
}
"Nice One Program"
#include<iostream.h>
#include<conio.h>
int main()
{ clrscr();
int n;
//int a[]={7,25,22,5,4,60,20,11,2,9}; //taking cont elements
int *a=NULL; //dynamic array
cout<<"enter numb of elemnt:";
cin>>n;
a=new int[n];
int temp,i,j,A,B;
cout<<"\n\nenter elements:";
for(i=0;i<n;i++)
cin>>a[i]; //Input Values
cout<<"\n\nBefore sorting";
for(i=0;i<n;i++)
cout<<a[i]<<" "; //Before
for(i=0;i<n;i++)
for(j=0;j<n-1-i;j++) //Sorting
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
cout<<endl<<"\nAfter Sorting:";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
getch();
return 0;
}
No comments:
Post a Comment