#include<iostream>
#include<stdlib.h>
using namespace std;
#include<conio.h>
int main()
{ char c='y';
while(c=='y' || c=='Y')
{
int a[20],j,count,n,temp;
cout<<"\nEnter number of elements to enter:";
cin>>n;
cout<<"\nEnter the elements:";
for(int i=0;i<n;i++)
{
cout<<endl;
cin>>a[i];
}
for(int i=0;i<n-1;i++)
{cout<<endl<<"****"<<endl;
count=0;
for(j=1;j<n-i;j++)
if(a[j]>a[count])
count=j;
swap(a[count],a[j-1]);//default swap function working in code blocks IDE or just change the code for explicit swapping
cout<<"\nAfter pass "<<i+1<<": ";
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
}
cout<<"\n\n******\n\nFinal Sorted array is:";
for(int i=0;i<n;i++)
cout<<" "<<a[i];
cout<<"\n\nWant to continue?(Y/N): ";
cin>>c;
system("cls");
}
}
#include<stdlib.h>
using namespace std;
#include<conio.h>
int main()
{ char c='y';
while(c=='y' || c=='Y')
{
int a[20],j,count,n,temp;
cout<<"\nEnter number of elements to enter:";
cin>>n;
cout<<"\nEnter the elements:";
for(int i=0;i<n;i++)
{
cout<<endl;
cin>>a[i];
}
for(int i=0;i<n-1;i++)
{cout<<endl<<"****"<<endl;
count=0;
for(j=1;j<n-i;j++)
if(a[j]>a[count])
count=j;
swap(a[count],a[j-1]);//default swap function working in code blocks IDE or just change the code for explicit swapping
cout<<"\nAfter pass "<<i+1<<": ";
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
}
cout<<"\n\n******\n\nFinal Sorted array is:";
for(int i=0;i<n;i++)
cout<<" "<<a[i];
cout<<"\n\nWant to continue?(Y/N): ";
cin>>c;
system("cls");
}
}
No comments:
Post a Comment