insertion sort.cpp
void insertion_sort(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=0; i<n; ++i){
		int j=i;
		while(j>0 && a[j]<a[j-1]){
			swap(a[j], a[j-1]);
			j--;
		}
	}
	for(int i=0; i<n; i++) cout<<a[i]<<" ";
	
}
/*
choose one element put that element at the correct position it is called insertion sort
*/
choose one element put that element at the correct position it is called insertion sort
choose one element put that element at the correct position it is called insertion sort
void insertion_sort(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=0; i<n; ++i){
		int j=i;
		while(j>0 && a[j]<a[j-1]){
			swap(a[j], a[j-1]);
			j--;
		}
	}
	for(int i=0; i<n; i++) cout<<a[i]<<" ";
}
void insertion_sort ( ) { int n ; cin >> n ; int a [ n ] ; for ( int i = 0 ; i < n ; i ++ ) cin >> a [ i ] ; for ( int i = 0 ; i < n ; ++ i ) { int j = i ; while ( j > 0 && a [ j ] < a [ j - 1 ] ) { swap ( a [ j ] , a [ j - 1 ] ) ; j -- ; } } for ( int i = 0 ; i < n ; i ++ ) cout << a [ i ] << " " ; }
choose one element put that element at the correct position it is called insertion sort
choose one element put that element at the correct position it is called insertion sort