Question: Write a C programming function for: 1. Batched version of finding the ranks for the num keys in the ordered array in[ ] // Search
Write a C programming function for:
1. Batched version of finding the ranks for the num keys in the ordered array in[ ]
// Search for a batch of ranks // out[i] gets result of STselect(in[i]) void STselectBatch(int num,int *in,Item *out);
USEFUL FUNCTIONS:
Item STselect(int k) { if (k<1 || k>head->N) { printf("Range error in STselect() k %d N %d ",k,head->N); exit(0); } return selectR(head, k); }
Item selectR(link h, int i) // Returns the ith smallest key where i=1 returns the smallest // key. Thus, this is like flattening the tree inorder into an array // and applying i as a subscript. { int r = h->l->N+1;
if (h == z) { printf("Impossible situation in selectR "); STprintTree(); exit(0); } if (i==r) return h->item; if (i
void STprintTree() { printTree(head,0,leftPathBlackHeight(head)); }
void printTree(link h,int depth,int bhAbove) { int i,bhBelow;
if (h==z) { if (bhAbove!=1) { for (i=0;i return; } int leftPathBlackHeight(link h) // Counts black nodes on path to the minimum { if (h==z) return !(h->red); return leftPathBlackHeight(h->l) + !(h->red); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
