// shellitst.cc for comparison with shellitst.ada and shellitst.f90 // shelli.h typedef char a_names[20][4]; typedef float a_balances[20]; void shelli(int size, a_names arr1, a_balances arr2); // shelli.cc #include void shelli(int size, a_names arr1, a_balances arr2) { int i, m; char temp1[4]; // must be same as second subscript of a_names float temp2; m=size; while (m>1){ m=m/2; for(int j=1; j<=size-m; j++){ i=j; while(i>0){ if(strncmp(arr1[i-1],arr1[i+m-1],3)>0){ strncpy(temp1,arr1[i-1],3); strncpy(arr1[i-1],arr1[i+m-1],3); strncpy(arr1[i+m-1],temp1,3); temp2=arr2[i-1]; arr2[i-1]=arr2[i+m-1]; arr2[i+m-1]=temp2; i=i-m; } else break; } } } } // shellitst.cc #include // #include "shelli.h" commented out because physically in this file int main(void) { a_names arr1 = {"MMM","NNN","AAA","CCC","BBB","ZZZ","XXX", "PPP","QQQ","DDD","EEE","FFF","GGG","HHH", "III","JJJ","KKK","LLL","OOO","RRR"}; a_balances arr2 = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14., 15.,16.,17.,18.,19.,20.}; for(int i=0; i<20; i++) printf("%c%c%c %f \n", arr1[i][0], arr1[i][1], arr1[i][2], arr2[i]); shelli(20, arr1, arr2); printf("Sorted by name \n"); for(int i=0; i<20; i++) printf("%c%c%c %f \n", arr1[i][0], arr1[i][1], arr1[i][2], arr2[i]); return 0; }