mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-04 02:59:43 +08:00
style: format code
This commit is contained in:
@@ -1,41 +1,40 @@
|
||||
//Insertion Sort
|
||||
|
||||
#include<iostream>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cout<<"\nEnter the length of your array : ";
|
||||
cin>>n;
|
||||
cout << "\nEnter the length of your array : ";
|
||||
cin >> n;
|
||||
int Array[n];
|
||||
cout<<"\nEnter any "<<n<<" Numbers for Unsorted Array : ";
|
||||
|
||||
cout << "\nEnter any " << n << " Numbers for Unsorted Array : ";
|
||||
|
||||
//Input
|
||||
for(int i=0; i<n; i++)
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cin>>Array[i];
|
||||
cin >> Array[i];
|
||||
}
|
||||
|
||||
|
||||
//Sorting
|
||||
for(int i=1; i<n; i++)
|
||||
for (int i = 1; i < n; i++)
|
||||
{
|
||||
int temp=Array[i];
|
||||
int j=i-1;
|
||||
while(j>=0 && temp<Array[j])
|
||||
int temp = Array[i];
|
||||
int j = i - 1;
|
||||
while (j >= 0 && temp < Array[j])
|
||||
{
|
||||
Array[j+1]=Array[j];
|
||||
Array[j + 1] = Array[j];
|
||||
j--;
|
||||
}
|
||||
Array[j+1]=temp;
|
||||
Array[j + 1] = temp;
|
||||
}
|
||||
|
||||
//Output
|
||||
cout<<"\nSorted Array : ";
|
||||
for(int i=0; i<n; i++)
|
||||
{
|
||||
cout<<Array[i]<<"\t";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Output
|
||||
cout << "\nSorted Array : ";
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cout << Array[i] << "\t";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user