0

Is this insertion sort?

I want to know whether it is insertion sort if not what is the difference between real and this implementation. #include<stdio.h> #include<stdlib.h> int main() { int n; puts("Enter the number of elements"); scanf("%d",&n); int *arr; arr=(int*)malloc(n*sizeof(int)); for(int i=0; i<n; i++) { scanf("%d",(arr+i)); } for(int i=1; i<n; i++) { while(arr[i]<arr[i-1] && i>0) { int temp=arr[i]; arr[i]=arr[i-1]; arr[i-1]=temp; i--; } } for(int i=0; i<n; i++) { printf("%d ",*(arr+i)); } }

23rd Jun 2019, 5:37 PM
Jiazz
Jiazz - avatar
2 odpowiedzi
+ 3
it's bubble sort
23rd Jun 2019, 5:45 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 3
23rd Jun 2019, 5:48 PM
Anna
Anna - avatar