예제 #1
0
 TreeNode* deleteNode(TreeNode* t, int key) {
   if (t == NULL)
     return NULL;
   if (t->val < key) {
     t->right = deleteNode(t->right, key);
   } else if (t->val > key) {
     t->left = deleteNode(t->left, key);
   } else {
     if (t->left == NULL) {
       TreeNode* u = t->right;
       delete t;
       return u;
     } else if (t->right == NULL) {
       TreeNode* u = t->left;
       delete t;
       return u;
     }
     TreeNode* u = getMinNode(t->right);
     t->val = u->val;
     t->right = deleteNode(t->right, u->val);
   }
   return t;
 }
예제 #2
0
파일: maze1.c 프로젝트: wentcui/usaco
void findMaxDist(int sx, int sy, int nodes[100][38]) {
	int i, j;
	int mx, my;
	int can_nodes[100][38];
	int max = -1;
	for(i = 0; i < 100; i++) {
		for(j = 0; j < 38; j++) {
			nodes[i][j] = -1;
			can_nodes[i][j] = 4000;
		}
	}

	can_nodes[sx][sy] = 0;
	while(1) {
		mx = my = -1;
		getMinNode(can_nodes, &mx, &my);
		if (mx == -1 || my == -1)
			break;

		nodes[mx][my] = can_nodes[mx][my];
		incrAllNh(mx, my, nodes, can_nodes);
		can_nodes[mx][my] = 4000;
	}
}
예제 #3
0
const void *TreeSetImpl::getMin() const {
  return getMinNode()->key();
}