int main(){ int a[100],a2[100],a3[100],a4[100]; int len; int i; printf("Enter the length of the array : "); scanf("%d",&len); for(i = 0 ; i< len ; i++){ scanf("%d",&a[i]); a2[i] =a3[i] = a4[i]=a[i]; } sort_1(&a[0],len); sort_2(&a2[0],len); sort_3(&a3[0],len); sort_4(&a4[0],len); return 0; }
idw idw_sort (idw a,idw b,idw c,idw d) { int index[32] = {0}; sui s[17] = {0}; sui tmp[12]; idw ans; int used = 0; int i,j,k,m,n; // for a; { i = hash(a.id.x,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = a.id.x; s[j].w += a.w.x; i = hash(a.id.y,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = a.id.y; s[j].w += a.w.y; i = hash(a.id.z,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = a.id.z; s[j].w += a.w.z; i = hash(a.id.w,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = a.id.w; s[j].w += a.w.w; } // for b; { i = hash(b.id.x,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = b.id.x; s[j].w += b.w.x; i = hash(b.id.y,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = b.id.y; s[j].w += b.w.y; i = hash(b.id.z,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = b.id.z; s[j].w += b.w.z; i = hash(b.id.w,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = b.id.w; s[j].w += b.w.w; } // for c; { i = hash(c.id.x,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = c.id.x; s[j].w += c.w.x; i = hash(c.id.y,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = c.id.y; s[j].w += c.w.y; i = hash(c.id.z,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = c.id.z; s[j].w += c.w.z; i = hash(c.id.w,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = c.id.w; s[j].w += c.w.w; } // for d; { i = hash(d.id.x,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = d.id.x; s[j].w += d.w.x; i = hash(d.id.y,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = d.id.y; s[j].w += d.w.y; i = hash(d.id.z,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = d.id.z; s[j].w += d.w.z; i = hash(d.id.w,index,s); j = 0==index[i]?++used:index[i]; index[i] = j; s[j].id = d.id.w; s[j].w += d.w.w; } sort_4(s+1); sort_4(s+5); sort_4(s+9); sort_4(s+13); merge_sort (s+1,s+5,tmp+8); merge_sort (tmp+8,s+9,tmp+4); merge_sort (tmp+4,s+13,tmp); ans.id.x = tmp[0].id; ans.w.x = tmp[0].w; ans.id.y = tmp[1].id; ans.w.y = tmp[1].w; ans.id.z = tmp[2].id; ans.w.z = tmp[2].w; ans.id.w = tmp[3].id; ans.w.w = tmp[3].w; return ans; }