示例#1
0
文件: maze.c 项目: funning/algorithm
int dealNodeR(int myMaze[][9], Queue* queue, Postion* current, Postion start, Postion end) {
	int match = 1, i = 0;
	int x = current->x, y = current->y, tmp = 0;
	Postion* p[6] = {0};
	tmp = x + 1;
	if (dealNode(myMaze, tmp, y, end, myMaze[y][x], &(p[i++])) == 1) {
		goto EXIT;
	}
	tmp = x - 1;
	if (dealNode(myMaze, tmp, y, end, myMaze[y][x], &(p[i++])) == 1) {
		goto EXIT;
	}
	tmp = y + 1;
	if (dealNode(myMaze, x, tmp, end, myMaze[y][x], &(p[i++])) == 1) {
		goto EXIT;
	}
	tmp = y - 1;
	if (dealNode(myMaze, x, tmp, end, myMaze[y][x], &(p[i++])) == 1) {
		goto EXIT;
	}
	match = 0;
	i = 0;
	for (;i<=3;i++) {
		if (p[i]) {
			QueueAdd(queue, p[i]);
		}
	}
EXIT:
	while(p[i]) {
		tk_free(p[i]);
		i++;
	}
	return match;
}
示例#2
0
static void _bookkeeper_mem_destroy(void) {
	int i;
	static int tk_bookkeeper_mem_destroy_in_work = TK_FALSE;
	if(tk_bookkeeper_mem_destroy_in_work != TK_FALSE)//´Ë¾²Ì¬±äÁ¿µÄ¸³ÖµºÍÅжÏÊÇ·ÀÖ¹ºÍÄÚ´æÉêÇ뻥Ïàµ÷ÓÃÐг̵ݹ顣
		return;
	tk_bookkeeper_mem_destroy_in_work = TK_TRUE;
	for(i=0 ; i<_file_count ; ++i)
		tk_free(_file_names[i]);
	tk_free(_file_names);
	tk_free(_malloc_ptrs);
	_file_names = TK_NULL;
	_malloc_ptrs = TK_NULL;
	_file_count = 0;
	_malloc_count = 0;
	_malloc_size = 0;
	tk_bookkeeper_mem_destroy_in_work = TK_FALSE;
}
示例#3
0
文件: maze.c 项目: funning/algorithm
void markPoit(int myMaze[][9], stack* s, Postion end) {
	Postion* p = stack_pop(s);
	Queue* q = QueueInit();
	Postion current = end;
	while(p != 0) {
		if (isNear(*p, current) == 1) {
			myMaze[p->y][p->x] = 1;
			current = *p;
			QueueAdd(q, p);
		} else {
			tk_free(p);
		}
		p = stack_pop(s);
	}
	p = QueueGet(q);
	printf("(5,5)");
	while(p != 0) {
		printf("<-(%d,%d)", p->x, p->y);
		tk_free(p);
		p = QueueGet(q);
	}
	printf("\n");
	QueueDestory(q);
}
示例#4
0
文件: test11_1.c 项目: tkokamo/takos
int test11_1_main(int argc, char *argv[])
{
  char *p;
  int size;

  puts("test11_1 started\n");

  /*recv in static*/
  puts("test11_1 recv in.\n");
  tk_recv(MSGBOX_ID_MSGBOX1, &size, &p); /*recv*/
  puts("test11_1 recv out.\n");
  puts(p);

  /*recv dynamic msg */
  puts("test11_1 recv in.\n");
  tk_recv(MSGBOX_ID_MSGBOX1, &size, &p);
  puts("test11_1 recv out.\n");
  puts(p);
  tk_free(p);

  /*send static msg*/
  puts("test11_1 send in.\n");
  tk_send(MSGBOX_ID_MSGBOX2, 15, "static memory\n");
  puts("test11_1 send out.\n");

  /*send dynamic msg*/
  p = tk_malloc(18);
  strcpy(p, "allocated memory\n");
  puts("test11_1 send in.\n");
  tk_send(MSGBOX_ID_MSGBOX2, 18, p);
  puts("test11_1 send out.\n");

  puts("test11_1 exit.\n");

  return 0;
}
示例#5
0
文件: maze.c 项目: funning/algorithm
int visit2(int i, int j) {
	node* s = tk_calloc(1, I * J * sizeof(node));
	node* s1 = tk_calloc(1, I * J * sizeof(node));
	int p = 0;
	int p1[1] = {0};
	s[p].nodei = i;
	s[p].nodej = j;
	p++;
	do{
		int n, m;
		int havenext = 0;
		p--;
		m = s[p].nodei;
		n = s[p].nodej;
		maze[m][n] = 1;
		s1[p1[0]].nodei = m;
		s1[p1[0]].nodej = n;
		(p1[0])++;
		if (m == endI && n == endJ)
			success = 1;
		printf("visit2 maze[%d][%d] = %d, maze[%d][%d] = %d, maze[%d][%d] = %d, maze[%d][%d] = %d, maze[%d][%d] = %d, success = %d\n", m, n, maze[m][n], m, n + 1, maze[m][n + 1], m + 1, n, maze[m + 1][n], m, n - 1, maze[m][n - 1], m - 1, n, maze[m - 1][n], success);
		if (success != 1) {
			if (maze[m][n + 1] == 0) {
				havenext++;
				s[p].nodei = m;
				s[p].nodej = n + 1;
				p++;
			}

			if (maze[m + 1][n] == 0) {
				havenext++;
				s[p].nodei = m + 1;
				s[p].nodej = n;
				p++;
			}
			if (maze[m][n - 1] == 0) {
				havenext++;
				s[p].nodei = m;
				s[p].nodej = n - 1;

				p++;
			}
			if (maze[m - 1][n] == 0) {
				havenext++;
				s[p].nodei = m - 1;
				s[p].nodej = n;
				p++;
			}
		}
		if (success == 1)
			break;
		if (havenext == 0) {int a[1] = {0};
			printf("clear_foot \n");
			maze[m][n] = 6;
			clear_foot(s, p - 1, s1, p1);
			print_maze();
//			scanf("%d", a);
		}
	}while(p != 0);
	printf("maze[i][j] = %d\n", maze[i][j]);
	if (s)
		tk_free(s);
	if (s1)
		tk_free(s1);

	return success;
}
示例#6
0
文件: maze.c 项目: funning/algorithm
int norecursive(int i, int j) {
	stack* stack = stack_init(1);
	node* root = tk_calloc(1, sizeof(node));
	root->nodei = i;
	root->nodej = j;
	stack_push(stack, root);
	do{
		int n, m;
		node* temp = stack_pop(stack);
		printf("norecursive temp = %p, current_stacklist = %d\n", temp, stack_current(stack));
		m = temp->nodei;
		n = temp->nodej;
		if (temp->state == 1) {
			if (maze[m][n] == 1 && success == 0)
				maze[m][n] = 0;
			else
				maze[m][n] = 1;
			if (m == endI && n == endJ)
				success = 1;
			printf("norecursive maze[%d][%d] = %d, maze[%d][%d] = %d, maze[%d][%d] = %d, maze[%d][%d] = %d, maze[%d][%d] = %d, success = %d\n", m, n, maze[m][n], m, n + 1, maze[m][n + 1], m + 1, n, maze[m + 1][n], m, n - 1, maze[m][n - 1], m - 1, n, maze[m - 1][n], success);
		} else {
			if (success != 1) {
				node* next = tk_calloc(1, sizeof(node));
				next->state = 1;
				next->nodei = m;
				next->nodej = n;
				stack_push(stack, next);
				if (maze[m][n + 1] == 0) {
					next = tk_calloc(1, sizeof(node));
					next->state = 0;
					next->nodei = m;
					next->nodej = n + 1;
					stack_push(stack, next);
				}

				if (maze[m + 1][n] == 0) {
					next = tk_calloc(1, sizeof(node));
					next->state = 0;
					next->nodei = m + 1;
					next->nodej = n;
					stack_push(stack, next);
				}
				if (maze[m][n - 1] == 0) {
					next = tk_calloc(1, sizeof(node));
					next->state = 0;
					next->nodei = m;
					next->nodej = n - 1;
					stack_push(stack, next);
				}
				if (maze[m - 1][n] == 0) {
					next = tk_calloc(1, sizeof(node));
					next->state = 0;
					next->nodei = m - 1;
					next->nodej = n;
					stack_push(stack, next);
				}
				next = tk_calloc(1, sizeof(node));
				next->state = 1;
				next->nodei = m;
				next->nodej = n;
				stack_push(stack, next);
			}
		}
		tk_free(temp);
	}while(stack_empty(stack) == 0);
	printf("gggggggg maze[i][j] = %d\n", maze[i][j]);
	stack_destory(stack);
	tk_bookkeeper_mem_report();
	return success;
}