Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Find Triplets or Duplets that the sum is multiplie of three
Simulare 2022
Test1
Sum of digits of number
riemann
list
same
team name
iviewb
26 და 28 მარტს დამუშავებული
Please log in to post a comment.