Is this insertion sort ?? Please check...
After watching animated presentation of insertion sort , I tried to implement it by myself....But I am not sure , whether I have implemented it correctly . So please guys check it and leave comments... #include <iostream> using namespace std ; int main() { int n ,r ,z , temp; cin >> n ; int arr[n]; for(r=0;r<n;r++) { cin >> arr[r] ; } for(r=1;r<n;r++) { for(z=r;z>0;z--) { if(arr[z-1] > arr[z]) { temp = arr[z-1] ; arr[z-1] = arr[z] ; arr[z] = temp ; } else { break ; } } } for(r=0;r<n;r++) { cout << arr[r] << endl ; } return 0; }