void interpret(int a[], int *np, int N) { char command[2]; char key[2]; int p; while (command[0] != 'q') { printf("\nInput command ->"); scanf("%1s", command); scanf("%1s", &key); switch (command[0]) { case 'i' : case 'I' : if (*np < N) { bi_insert(key[0], a, np); printf("\n Successful insert."); } else printf("\n Error : Table full."); break; case 'd' : case 'D' : if (bi_delete(key[0], a, np) < 0) printf("\n Error : Table Empty."); else printf("\n Successful delete."); break; case 's' : case 'S' : if ((p = bi_search(key[0], a, *np)) < 0) printf("\n Error : Can'f find that key"); else printf("\n Ok! find in %d th position", p); break; case 'f' : case 'F' : if ((p = bii_search(key[0], a, *np)) < 0) printf("\n Error : Can't find that key"); else printf("\n Ok ! find in %d th position & move front", p); break; case 'l' : case 'L' : bi_list(a, *np); break; } printf(" n = %d", *np); } }
for (i = 0; i < n; i++) { rec.key = fixed_lump(7); rec.val = rnd_lump(); r_add(rec); bi_insert(&tree, rec); } r_for_each(find_find, &tree); bi_audit(&tree); } void delete (Lump_s key, Lump_s val, void *user) { BiTree_s *tree = user; int rc; rc = bi_delete(tree, key); if (rc) { fatal("Didn't find %s : rc=%d", key.d, rc); } } void test_bi_delete(int n) { BiTree_s tree = { 0 }; Rec_s rec; unint i; if (FALSE) seed_random(); for (i = 0; i < n; i++) { rec.key = fixed_lump(7); rec.val = rnd_lump();