int main(void) { LLIST *handle = NULL, *find = NULL; int len; handle = llist_load("./db", destroy, store, load); if (handle == NULL) { printf("llist_load!\n"); return 0; } llist_travel(ls, NULL, handle); while (1) { printf("please input id : "); scanf("%d", &len); if (len == -1) break; find = llist_findall(&len, cmp_id, handle); if (find != NULL) { printf("find : \n"); llist_travel_find(ls, NULL, find); } } llist_destroy(&handle); return 0; }
int main(void) { struct score tmp, *datap; int i, id; LLIST *list; int ret; list = llist_creat(sizeof(struct score)); for (i = 0; i < 7; i++) { tmp.id = i; tmp.math = 100 - i; snprintf(tmp.name, NAMESIZE, "stu%d", i); llist_insert(list, &tmp, LLIST_BACKWARD); } llist_travel(list, print_s); id = 4; ret = llist_fetch(list, &tmp, &id, id_cmp); printf("\n"); if (ret == -1) { printf("Can not find.\n"); } else { print_s(&tmp); } printf("\n"); llist_travel(list, print_s); #if 0 id = 8; llist_delet(list, &id, id_cmp); printf("\n"); llist_travel(list, print_s); id = 2; datap = llist_find(list, &id, id_cmp); if (datap == NULL) { printf("Can not find.\n"); } else { print_s(datap); } #endif llist_save(list, "stu.data"); llist_destroy(list); LLIST *list2 = llist_load("stu.data"); llist_travel(list2, print_s); llist_destroy(list2); return 0; }
int main(int argc, char *argv[]) { LLIST *handle = NULL, *find = NULL; int n; if (argc > 1) handle = llist_load("./db"); else { handle = llist_create(sizeof(int)); while (1) { printf("please input num : "); scanf("%d", &n); if (n == -1) break; /*llist_append(&n, handle);*/ /*llist_prepend(&n, handle);*/ /*llist_insert(&n, PREPEND, handle);*/ llist_sort_insert(&n, cmp, handle); } llist_travel(ls, NULL, handle); printf("\n"); n = 9999; llist_insert(&n, 3, handle); if (!llist_store("./db", handle)) printf("存储成功!\n"); } llist_travel(ls, NULL, handle); printf("\n"); llist_sort(cmp, handle); printf("sort : "); llist_travel(ls, NULL, handle); printf("\n"); while (1) { printf("please input key : "); scanf("%d", &n); if (n == -1) break; find = llist_findall(&n, cmp, handle); if (find != NULL) { llist_travel_find(ls, NULL, find); printf("\n"); } /* * printf("delete = %d\n", llist_delete(&n, cmp, handle)); * * llist_travel(ls, NULL, handle); * printf("\n"); */ } llist_destroy(&handle); return 0; }