Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
IndiSort
//g++ 7.4.0 //Indirect sort: sorting an array indirectly with the aid of index so that original array left undisturbed //code credit goes to John R. Hubbard,University of Richmond #include <iostream> using namespace std; const int n=8; void print( int [],const int); void sort(int [],int [], int); void print(int [],int [], int); void print(int a[],const int n) { cout<<"\nOriginal array:\n"; for(int i=0;i<n;i++){ cout<<" "<<a[i];} cout<<"\n"; } void sort(int a[],int index[],int n){ for(int i=1;i<n;i++) for(int j=0; j<n-i; j++) if(a[index[j]]>a[index[j+1]]){ int temp; temp = index[j]; index[j]= index[j+1]; index[j+1]=temp; } } void print(int a[],int index[], const int n){ cout<<"Indirect sorted array:\n"; for (int i=0;i<n;i++) cout<<" "<<a[index[i]]; } int main(){ int a[8]={7,8,4,5,2,10,9,11}; int index[8]={0,1,2,3,4,5,6,7}; print(a,8); sort(a,index,8); print(a,index,8); print(a,8); return 0; }
run
|
edit
|
history
|
help
0
Lockable static queue
NonparaSign
Newspaper
Program
avx2 optimized pcg32 random number generator
RecursiveFact
reverseKNode
СПКИ АП КЭП 3
Sort an array of 0s, 1s and 2s
cccc