示例#1
0
文件: main.c 项目: zyxstar/exam_c
int main(void)
{
	struct score tmp, *p;
	LLIST *list;
	int i;

	list = llist_creat(sizeof(struct score));
	/* if error */

	for (i = 0; i < 9; i++) {
		tmp.id = i;
		tmp.ch = 100 - i;
		tmp.math = 100 - i * 2;
		tmp.en = 100 - i * 3;
		snprintf(tmp.name, NAMESIZE, "stu%d", i);

		llist_add(list, &tmp, LLIST_ADD_FORWARD);
	}

	llist_travel(list, print_score);
	llist_delet(list, "stu6", name_cmp);
	printf("\n");
	llist_travel(list, print_score);
#if 0
	p = llist_find(list, "stuxx", name_cmp);
	if (p == NULL) {
		printf("Can not find.\n");
	} else {
		print_score(p);
	}
#endif

	llist_destroy(list);
	return 0;
}
示例#2
0
文件: main.c 项目: wcybxzj/shangguan
//变长结构体版本
//类的概念:数据和方法都放入头节点
int main(int argc, const char *argv[])
{
	int i, ret;
	LLIST *handler;
	SCORE_ST tmp, *tmp_p;
	handler = llist_creat(sizeof(SCORE_ST));

	for (i = 0; i < 7; i++) {
		tmp.id = i;
		snprintf(tmp.name, NAMESIZE, "middle school student%d", i);
		tmp.math = rand() %100;
		tmp.chinese = rand() %100;
		//myprint(&tmp);
		llist_insert(handler, &tmp, LLIST_FORWARD);
	}

	llist_travel(handler, myprint);

	printf("-----------------------------------\n");

	char *name = "stu3";
	tmp_p = llist_find(handler, name, cmp_name);
	if (tmp_p) {
		myprint(tmp_p);
	}else{
		printf("not find\n");
	}

	printf("-----------------------------------\n");
	int id = 2;
	ret = llist_fetch(handler, &id, cmp_id, &tmp);
	if (ret) {
		printf("fetch ");
		myprint(&tmp);
	}

	printf("-----------------------------------\n");
	name ="stu0";
	ret = llist_delete(handler, name, cmp_name);
	if (ret) {
		printf("delete %s\n", name);
	}
	printf("-----------------------------------\n");
	llist_travel(handler, myprint);
	printf("-----------------------------------\n");

	name = malloc(NAMESIZE);
	for (i = 1; i < 7; i++) {
		snprintf(name, NAMESIZE, "stu%d", i);
		ret = llist_delete(handler, name, cmp_name);
		if (ret) {
			printf("delete %s\n", name);
		}
	}
	llist_travel(handler, myprint);

	llist_destroy(handler);
	return 0;
}
示例#3
0
文件: main.c 项目: zyxstar/exam_c
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;
}
示例#4
0
文件: main.c 项目: harkhuang/harkcode
int main()
{
	struct score tmp,*datap;
	int i,id,ret;
	char name[] = "sstu1";
	LLIST *handle;

	handle = llist_create(sizeof(struct score));
	if(handle == NULL)
		return -1;

	for(i = 0; i < 6 ;i++)
	{
		tmp.id = i;
		tmp.math = 100-i;
		snprintf(tmp.name,NAMESIZE,"stu%d",i);

		llist_insert(handle,&tmp,LLIST_BACKWARD);
		
	}
	
	llist_travel(handle,print_s);
	printf("\n\n");
	id = 3;

	ret = llist_fetch(handle,&id,id_cmp,&tmp);
	if(ret != -1)
		print_s(&tmp);
	printf("\n\n");
	llist_travel(handle,print_s);

	llist_destroy(handle);

//	llist_delete(handle,&id,id_cmp);
//	llist_travel(handle,print_s);


#if 0	
//	datap = llist_find(handle,&id,id_cmp);
	datap = llist_find(handle,name,name_cmp);
	if(datap == NULL)
		printf("can not find!\n");
	else
		print_s(datap);
#endif


	return 0;
}
示例#5
0
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;
}
示例#6
0
文件: main.c 项目: zyxstar/exam_c
int main(void)
{
	LLIST *llist;
	struct score tmp, *datap;
	int i;
	int id;
	struct sum_st sum = {0,0};

	llist = llist_creat(sizeof(struct score));
	/* if error */

	for (i = 0; i < 7; i++) {
		tmp.id = i;
		snprintf(tmp.name, NAMESIZE, "stu%d", i);
		tmp.ch = 100 - i;
		tmp.math = 100 - 2 * i;

		llist_insert(llist, &tmp);
		/* if error */
	}

	llist_travel(llist, print_score, NULL);
	printf("\n");

#if 1
	id = 3;
	llist_delet(llist, &id, id_cmp);
	llist_travel(llist, print_score, NULL);
#else
	datap = llist_find(llist, &id, id_cmp);
	if (datap == NULL) {
		printf("Can not find.\n");
	} else {
		print_score(datap, NULL);
	}
	llist_travel(llist, get_sum, &sum);
	printf("sum: ch = %d, math = %d\n", sum.ch, sum.math);
#endif

	llist_destroy(llist);

	return 0;
}
示例#7
0
int main()
{
	LLIST *handle;
	int i ,ret, id = 3;
    char *name = "person2";
	struct person_st tmp, *datap;
	
	handle = llist_create(sizeof(struct person_st));
	if(handle== NULL)
		return -1;
	
	for(i = 0; i < 6; i++)
	{
		tmp.id = i;
		tmp.age = 20 + i;
		snprintf(tmp.name,NAMESIZE,"person%d",i);
		
		llist_insert(handle,&tmp,LLIST_FORWARD);
	}
	
	llist_travel(handle,print_s);
	printf("\n\n");

    ret =  llist_fetch(handle,name,name_cmp,&tmp);
    if(ret == 0)
        print_s(&tmp);
    printf("\n\n");
   
  //  llist_delete(handle,&id,id_cmp);
  //  llist_travel(handle,print_s);

#if 0
    //datap = llist_find(handle,&id,id_cmp);
    datap = llist_find(handle,name,name_cmp);
        if(datap == NULL)
            printf("ca not find!\n");
        else
            print_s(datap);
#endif
	llist_destroy(handle);
	return 0;
}
示例#8
0
文件: test.c 项目: kissthink/notes
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;
}
示例#9
0
文件: ds_llist.c 项目: gwtony/wsocket
void func_test()
{
	char *s = "this is a test";
	char *s2 = "x";
	void *b;
	int i, j;
	llist_t *ll;

	/*
	 * test 1
	 */

	ll = llist_new(20);	
	for (i = 0; i < 4; i++) {
		if (i%3 == 0) {
			llist_append(ll, &s2[0]);
		}
		llist_append(ll, &s[i]);
	}
	
	llist_travel(ll, &show);
	printf("\n");
	for (i = 0; i < 4; i++) {
		llist_prepend(ll, &s[0]);
	}
	llist_travel(ll, &show);
	printf("\n");
	for (i = 0; i < 4; i++) {
		llist_prepend_nb(ll, &s[1]);
	}
	llist_travel(ll, &show);
	printf("\n");
	llist_fetch_head(ll, &b);
	llist_travel(ll, &show);
	printf("\n");
	llist_fetch_head(ll, &b);
	llist_travel(ll, &show);
	printf("\n");
	llist_delete(ll);
	
	printf("%stest1 successful%s\n", COR_BEGIN, COR_END);

	/*
	 * test 2
	 */

	ll = llist_new(1000);
	for (j = 0; j < 100; j++) {
		for (i = 0; i < 10; i++) {
			llist_append_nb(ll, &s[i]);
		}
	}
	printf("append done.\n");
	for (i = 0; i< 100; i++) {
		llist_fetch_head_nb(ll, &b);
		printf("%c", *(char *)b);
	}
	printf("\nthere are %d nodes\n", ll->nr_nodes);
	for (i = 0; i< 100; i++) {
		llist_get_head_nb(ll, &b);
		printf("%c", *(char *)b);
	}
	printf("\n");
	printf("%stest2 successful%s\n", COR_BEGIN, COR_END);
	printf("there are %d nodes\n", ll->nr_nodes);
	
	/*
	 * test 3
	 */
	void *ptr, *ptr2;
	llist_get_head_node_nb(ll, &ptr);
	for (i = 0; i< 100; i++) {
		printf("%c", *(char *)(((llist_node_t *)ptr)->ptr));
		ptr = llist_get_next_nb(ll, ptr);
	}
	printf("\nthere are %d nodes\n", ll->nr_nodes);
	llist_delete(ll);
	printf("%stest3 successful%s\n", COR_BEGIN, COR_END);
	return;
}
示例#10
0
int main(void)
{
    int n, ret;
    void *ret1;
    LLIST *handle = NULL;
    LLIST *find = NULL;
    
    handle = llist_create(sizeof(int), NULL, NULL, NULL);

    while (1)
    {
        printf("please input num : ");
        scanf("%d", &n);

        if (n == -1)
            break;

        llist_insert(&n, APPEND, handle);
    }
    
    llist_travel(printf_s, NULL, handle);
    printf("\n");

    printf("insert num : ");
    scanf("%d", &n);
    llist_insert(&n, 3, handle);
    llist_travel(printf_s, NULL, handle);
    printf("\n");

    printf("delete num : ");
    scanf("%d", &n);
    llist_delete(&n, cmp, handle);
    llist_travel(printf_s, NULL, handle);
    printf("\n");

	printf("find num : ");
	scanf("%d", &n);
	ret1 = llist_find(&n, cmp, handle);
    if(ret1 != NULL)
        printf("find = %d\n", *(int*)ret1);
    printf("\n");

    printf("findall num : ");
    scanf("%d", &n);
    find = llist_findall(&n, cmp, handle);
    llist_travel(printf_s, find, handle);
    printf("\n");

    llist_sort(cmp, handle);
    printf("sort:");
    llist_travel(printf_s, NULL, handle);
	printf("\n");

    ret = llist_store("./db", handle);
    if(ret == 0)
        printf("存储成功!\n");

    llist_destroy(&handle);

    return 0;
}