int num[6];
int number, tmp;
char choice;
void main(){
for(int i=0;i<5;i++){
cout<<"Enter Number : ";
cin>>number;
num[i]=number;
}
cout<<"\nUnsorted : \n";
for(int j=0;j<5;j++){
cout<<"\t "<
}
cout<<"\n\nChoices [i]Increasing || [d]Decreasing ";
cout<<"\nChoose ? : ";cin>>choice;
if(choice=='i'||choice=='I'){
for(int next=1;next<5;next++){
tmp=num[next];
int moveItem=next;
while((moveItem>0)&&(num[moveItem-1]>tmp))
{
num[moveItem]=num[moveItem-1];
moveItem--;
}
num[moveItem]=tmp;
}
cout<<"\nSorted[Increasing] Array : \n";
for(j=0;j<5;j++){
cout<<"\t "<
if(choice=='d'||choice=='D'){
for(int next=1;next<5;next++){
tmp=num[next];
int moveItem=next;
while((moveItem>0)&&(num[moveItem-1]>tmp))
{
num[moveItem]=num[moveItem-1];
moveItem--;
}
num[moveItem]=tmp;
}
cout<<"\nSorted[Increasing] Array : \n";
for(j=0;j<5;j++){
cout<<"\t "<
}
}
}
}
}
No comments:
Post a Comment