[ create a new paste ] login | about

Link: http://codepad.org/OAts1UzD    [ raw code | output | fork ]

C++, pasted on Sep 6:
#include <iostream>
using namespace std;
 
void arr_show(int * arr, int size);
void arr_sort(int * arr, int pos, int count, bool bascend = true);
 
int main(){
    int arr[] = {5, -3, 14, 44, -2, 11, 1, 3, 5, 17, 46};
    int size  = sizeof(arr) / sizeof(arr[0]);
    int pos   = 3;
    cout<<"\n\tINIT : "<<endl;
    arr_show(arr, size);
    arr_sort(arr, 0, pos, false);
    arr_sort(arr, pos + 1, size - pos - 1, true);
    cout<<"\n\tSORT : "<<endl;
    arr_show(arr, size);
    return 0;
}
void arr_show(int * arr, int size){
    for( int i = 0; i < size; i++ )
        cout<<arr[i]<<" ";
}
void arr_sort(int * arr, int pos, int count, bool bascend){
    int i, j, buf;
    for( i = pos; i < pos + count; i++ )
    for( j = pos; j < pos + count; j++ )
    {
        if( bascend ? (arr[i] > arr[j]) : (arr[i] < arr[j]) )
        {
            buf = arr[i];
            arr[i] = arr[j];
            arr[j] = buf;
        }
    }
}


Output:
1
2
3
4
5

	INIT : 
5 -3 14 44 -2 11 1 3 5 17 46 
	SORT : 
-3 5 14 44 46 17 11 5 3 1 -2 


Create a new paste based on this one


Comments: