codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#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; } } }
Private
[
?
]
Run code
Submit