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)); } }
2 Respuestas
+ 3
it's bubble sort
+ 3
Bubble sort, not too efficient
https://code.sololearn.com/c7lggmgQ9564/?ref=app