mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
insertion sort
This commit is contained in:
parent
e58c46237b
commit
5e3a0d49d0
27
InsertionSort.python
Normal file
27
InsertionSort.python
Normal file
|
@ -0,0 +1,27 @@
|
|||
|
||||
|
||||
array=[];
|
||||
|
||||
# input
|
||||
print ("Enter any 6 Numbers for Unsorted Array : ");
|
||||
for i in range(0, 6):
|
||||
n=input();
|
||||
array.append(int(n));
|
||||
|
||||
# Sorting
|
||||
print("")
|
||||
for i in range(1, 6):
|
||||
temp=array[i]
|
||||
j=i-1;
|
||||
while(j>=0 and temp<array[j]):
|
||||
array[j+1]=array[j];
|
||||
j-=1;
|
||||
array[j+1]=temp;
|
||||
|
||||
# Output
|
||||
for i in range(0,6):
|
||||
print(array[i]);
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user