SORTING ARRAY USING INNSERTION SORT

#include <iostream>

using namespace std;

int arr[5];

int main(){

cout<<"enter  5 random numbers that you want to sort"<<endl;

for(int x=0;x<5;x++){

cout<<"enter "<<x<<"st value = ";

cin>>arr[x];

cout<<endl;


}
for (int x=0;x<5;x++){

for(int y=0;y<5-x-1;y++){

if(arr[y]>arr[y+1]){

int temp=arr[y+1];

arr[y+1]=arr[y];

arr[y]=temp;
}

}
}
for(int x=0;x<5;x++){

cout<<arr[x];

cout<<"   ";

}
}
Previous
Next Post »

Comments:

Disqus Shortname