/* shellitst.c for comparison with shellitst.ada and shellitst.f90 */ /* shelli.h function prototype */ typedef char a_names[20][3]; typedef float a_balances[20]; void shelli(int size, a_names arr1, a_balances arr2); /* shelli.c */ #include void shelli(int size, a_names arr1, a_balances arr2) { int i, j, m; char temp1[3]; float temp2; m=size; while (m>1){ m=m/2; for(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.c */ #include /* #include "shelli.h" commented out because physically in this file Ada allows moving code between files with no change */ 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.}; int i; for(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(i=0; i<20; i++) printf("%c%c%c %f \n", arr1[i][0], arr1[i][1], arr1[i][2], arr2[i]); return 1; }