예제 #1
0
void i_execute(SOURCE_FILE * sf)
{
	// pre scan
	l_scan(sf);
	// call main
	i_call_sub(sf,"main");
	// clean up
	list_destory(&list_var);
	list_destory(&list_sub);
	Bfile_CloseFile(sf->file);
	free(sf);
}
예제 #2
0
파일: lua_timer.c 프로젝트: sundoom/nova
VOID lua_timer_exit(lua_State* ls)
{
	if(s_timer_list)
	{
		while(list_size(s_timer_list) > 0)
		{
			timer_t* timer = (timer_t*)list_del(s_timer_list, s_timer_list->head);
			if(timer) FREE(timer);
		}
		list_destory(&s_timer_list);
	}
}
예제 #3
0
//销毁广义表
void list_destory(s_list *list)
{
	if (list == null)
	{
		return;
	}

	//如果下一节点不为空
	if (list->next != null)
	{
		//递归销毁下一节点
		list_destory(list->next);
	}

	//如果当前节点是子表
	if (list->tag)
	{
		//递归销毁子表
		list_destory(list->child);
	}

	free(list);
}
예제 #4
0
파일: main.c 프로젝트: Shimejing/demo_class
int main(void)
{
	int i, j;
	node_init(&address_list);
	char *menu[7] = {"1.新增联系人","2.更新联系人","3.查找联系人","4.查看","5.导出联系人","9.帮助","0.退出"};


	printf("----------------欢迎使用本通讯录-------------\n");
	for(;;){
		for( j = 0 ; j < 7 ; ++j){
			printf("%s\n", menu[j]);
		}
		printf("[0-5,9]:");
		scanf("%d",&i);
		printf("\n");
		switch(i){
			case 1 :
				add_link_man();
				break;
			case 2 :
				display_link_man(&address_list,print_linkman);
				update_link_man(&address_list);
				break;
			case 3 :
				find_link_man(&address_list);
				break;
			case 4 :
				display_link_man(&address_list,print_linkman);
				break;
			case 5 :
				if(save(&address_list) < 0){
					printf("save failed!\n");
				}else
					printf("save succeed!\n");
				break;
			case 0 :
				list_destory(&address_list);
				exit(-1);
				break;
			case 9 :
				help_info();
				break;
			default :
				break;
		}

	}
	return 0;
}
예제 #5
0
파일: main.c 프로젝트: wcybxzj/shangguan
int main(int argc, const char *argv[])
{
	int i, ret;
	int arr[] = {12, 9, -1, 23, 2, 34, 6, 45};
	list *ptr = NULL, *ptr2 = NULL; 
	ptr = list_create();
	ptr2 = list_create();
	if (NULL == ptr) {
		printf("error\n");
		exit(1);
	}

	for (i = 0; i < sizeof(arr)/sizeof(*arr); i++) {
		ret = list_insert_at(ptr, DATA_INIT_INDEX, &arr[i]);
		if (ret < 0) {
			fprintf(stderr, "isnert err %d\n", ret);
			exit(1);
		}
	}

	list_display(ptr);

	int tmp = 100;
	list_insert_at(ptr, 1, &tmp);
	list_display(ptr);
	list_destory(ptr);

	for (i = 0; i < sizeof(arr)/sizeof(*arr); i++) {
		ret = list_order_insert(ptr2, &arr[i]);
		if (ret < 0) {
			fprintf(stderr, "isnert err %d\n", ret);
			exit(1);
		}
	}

	list_display(ptr2);

	tmp = 23;
	list_delete(ptr2, &tmp);
	list_display(ptr2);

	list_delete_at(ptr2, 2, &tmp);
	printf("delete_at %d\n", tmp);
	list_display(ptr2);

	return 0;
}
예제 #6
0
파일: sort.cpp 프로젝트: wengduo/item
void xuhuan_quick_sort_lian(int *arr, int low, int high)
{
	NODE p;
	list_init(&p);
	list_push(&p, high);
	list_push(&p, low);
	while (!list_kong(&p))
	{
		list_pop(&p, &low);
		int p1 = low;
		list_pop(&p, &high);
		int p2 = high;
		int tmp = arr[low];
		while (low < high)
		{
			while (arr[high] >= tmp && low < high)
			{
				count++;
				high--;
			}
			arr[low] = arr[high];
			if (low < high)
			{
				low++;
			}
			while (arr[low] <= tmp && low < high)
			{
				count++;
				low++;
			}
			arr[high] = arr[low];
			if (low < high)
			{
				high--;
			}
		}
		arr[low] = tmp;
		if (p1 < p2)
		{
			list_push(&p, p2);
			list_push(&p, low + 1);
			list_push(&p, low - 1);
			list_push(&p, p1);
		}
	}
	list_destory(&p);
}
예제 #7
0
void graph_destroy(Graph *graph)
{
    AdjList *adjlist;

    // 移除每一个相邻的链表结构和链表
    while(list_size(&graph->adjlists) > 0) {
        if (list_rem_next(&graph->adjlists, NULL, (void **)&adjlist) == 0) {
            set_destroy(&adjlist->adjacent);

            if (graph->destroy != NULL) {
                graph->destroy(adjlist->vertex);
                free(adjlist);
            }
        }
    }

    list_destory(&graph->adjlists);
    memset(graph, 0 sizeof(Graph));
    return;
}
예제 #8
0
int main(int argc, char **args)
{
	//list1 x^10
	s_list *list1 = (s_list *) malloc(sizeof(s_list));
	list_init(list1);
	list_insert_value(list1, 0, 10, 1);

	//list2 2x^6
	s_list *list2 = (s_list *) malloc(sizeof(s_list));
	list_init(list2);
	list_insert_value(list2, 0, 6, 2);

	//list1 (x^10 + 2x^6)
	list_append(list1, list2);

	//list3 (x^10 + 2x^6)y^3
	s_list *list3 = (s_list *) malloc(sizeof(s_list));
	list_init(list3);
	list_insert_value(list3, 1, 3, (int) list1);

	//list4 3x^5
	s_list *list4 = (s_list *) malloc(sizeof(s_list));
	list_init(list4);
	list_insert_value(list4, 0, 5, 3);

	//list5 (3x^5)y^2
	s_list *list5 = (s_list *) malloc(sizeof(s_list));
	list_init(list5);
	list_insert_value(list5, 1, 2, (int) list4);

	//list3 ((x^10 + 2x^6)y^3 + (3x^5)y^2)
	list_append(list3, list5);

	//list6 ((x^10 + 2x^6)y^3 + (3x^5)y^2)z^2
	s_list *list6 = (s_list *) malloc(sizeof(s_list));
	list_init(list6);
	list_insert_value(list6, 1, 2, (int) list3);

	//list7 x^4
	s_list *list7 = (s_list *) malloc(sizeof(s_list));
	list_init(list7);
	list_insert_value(list7, 0, 4, 1);

	//list8 6x^3
	s_list *list8 = (s_list *) malloc(sizeof(s_list));
	list_init(list8);
	list_insert_value(list8, 0, 3, 6);

	//list8 (x^4 + 6x^3)
	list_append(list7, list8);

	//list9 (x^4 + 6x^3)y^4
	s_list *list9 = (s_list *) malloc(sizeof(s_list));
	list_init(list9);
	list_insert_value(list9, 1, 4, (int) list7);

	//list10 2y
	s_list *list10 = (s_list *) malloc(sizeof(s_list));
	list_init(list10);
	list_insert_value(list10, 0, 1, 2);

	//list9 ((x^4 + 6x^3)y^4 + 2y)
	list_append(list9, list10);

	//list11 ((x^4 + 6x^3)y^4 + 2y)z
	s_list *list11 = (s_list *) malloc(sizeof(s_list));
	list_init(list11);
	list_insert_value(list11, 1, 1, (int) list9);

	//list6 ((x^10 + 2x^6)y^3 + (3x^5)y^2)z^2 + ((x^4 + 6x^3)y^4 + 2y)z
	list_append(list6, list11);

	//list12 15
	s_list *list12 = (s_list *) malloc(sizeof(s_list));
	list_init(list12);
	list_insert_value(list12, 0, 0, 15);

	//list6 ((x^10 + 2x^6)y^3 + (3x^5)y^2)z^2 + ((x^4 + 6x^3)y^4 + 2y)z + 15
	list_append(list6, list12);

	//显示多项式
	list_display(list6, 'z');
	printf("\n");

	//求广义表list6深度
	int depth = 0;
	list_depth(list6, &depth);
	printf("depth = %d \n", depth);

	s_list *list13 = (s_list *) malloc(sizeof(s_list));
	list_copy(list13, list6);
	//显示多项式
	list_display(list13, 'z');
	printf("\n");

	//求广义表list13深度
	depth = 0;
	list_depth(list13, &depth);
	printf("depth = %d \n", depth);

	//销毁广义表,释放内存
	list_destory(list6);
	//销毁广义表,释放内存
	list_destory(list13);

	return 0;
}