void interpret(int a[], int *np, int N) { char command[2]; char key[2]; int k; void *p; while (command[0] != 'q') { printf("\nInput command ->"); scanf("%1s", command); scanf("%1s", &key); k = (int)key[0]; switch (command[0]) { case 'i' : case 'I' : if (*np < N) { lv_insert(&k, a, np, sizeof(int), intcmp); printf("\n Successful Insert."); } else printf("\n Error : Table full."); break; case 'd' : case 'D' : if (lv_delete(&k, a, np, sizeof(int), intcmp) == NULL) printf("\n Error : Table empty or can't find."); else printf("\n Successful delete."); break; case 's' : case 'S' : if ((p = lv_search(&k, a, np, sizeof(int), intcmp)) == NULL) printf("\n Error : Can'f find that key"); else printf("\n Ok! find in %d th position", ((char*)p-(char*)a)/sizeof(int)); break; case 'f' : case 'F' : if ((p = lfv_search(&k, a, np, sizeof(int), intcmp)) == NULL) printf("\n Error : Can't find that key"); else printf("\n Ok ! find in %d th position & move front", ((char*)p-(char*)a)/sizeof(int)); break; case 'l' : case 'L' : li_list(a, *np); break; } printf(" n = %d", *np); } }
void *lv_delete(void *key, void *base, size_t *num, size_t width, FCMP fcmp) { void *ip; int i; if (*num > 0) { if ((ip = lv_search(key, base, num, width, fcmp)) == NULL) return NULL; for (i = ((char*)ip - (char*)base)/width+1; i < *num; i++) memcpy(BASE(i-1), BASE(i), width); (*num)--; return ip; } return NULL; }
void lv_test(int a[], int n) { int i; int r; long t1, t2; t1 = get_tick(); r = random(30000); for (i = 0; i < LOOP; i++) lv_search(&r, a, &n, sizeof(int), intcmp); t2 = get_tick(); printf("\n lv_search %d loops ellapse %ld ticks.", LOOP, diff_tick(t1,t2)); t1 = get_tick(); r = random(30000); for (i = 0; i < LOOP; i++) lfv_search(&r, a, &n, sizeof(int), intcmp); t2 = get_tick(); printf("\n lfv_search %d loops ellapse %ld ticks.", LOOP, diff_tick(t1,t2)); }
larr_all() { if (lv_first) { lvbase = lv_init(tsave, atoi(yytext)); lvone = lvtwo = lvbase; } else { if (lv_search(lvbase, tsave) == NULL) { lvtwo = lv_add(lvone, tsave, atoi(yytext)); lvone = lvtwo; } else { yyredec(yytext); } } }
lvar_all() { if (lv_first) { lvbase = lv_init(yytext, 1); lvone = lvtwo = lvbase; } else { if (lv_search(lvbase, yytext) == NULL) { lvtwo = lv_add(lvone, yytext, 1); lvone = lvtwo; } else { yyredec(yytext); } } }