コード例 #1
0
ファイル: func.c プロジェクト: Gonefar/BinaryTree
int destroy_node(tree *pTree, char *words)
{
	node *search_result = NULL, *temp = NULL;
	search_result = (node *)search_node_by_content(pTree, words);

	if(search_result != NULL && search_result->left == NULL \
	&& search_result->right == NULL)
	{
		delete_leaf_node(pTree, search_result);
		
	}
	else if(search_result != NULL && (search_result->left != NULL \
		|| search_result->right != NULL))
		{
			if(search_result->wordsNum == 1)
				{
					relink_tree(pTree, search_result);					
				}
			else
				{
					search_result->wordsNum--;
				}

		}
	else
		{
			printf("No this data in the tree\n");
			return -1;
		}
	
	traverse2(pTree);
	return 0;
}
コード例 #2
0
ファイル: isSymetric.cpp プロジェクト: hmofrad/etc
bool traverse2(TreeNode* p, TreeNode* q) {
    if(p and q) {
        bool same = traverse2(p->left, q->right);
        if(p->val != q->val)
            return(false);
        if(same)
            same = traverse2(p->right, q->left);
        return(same);
    }
    else {
        if(!p and !q)
            return(true);
        else
            return(false);
    }
}
コード例 #3
0
ファイル: count4.c プロジェクト: Linn1024/asm
long long traverse2(vertex v)
{
    long long ans = 1;
    int i;
    for (i = 0; i < ALPHA; i++)
        if (edges[v][i] != -1)
        {
            edge e = edges[v][i];
            ans += length(e) - 1;
            ans += traverse2(to[e]);
        }
	return ans;
}
コード例 #4
0
ファイル: isSymetric.cpp プロジェクト: hmofrad/etc
bool isSymmetric(TreeNode* root) {
    bool symmetric = traverse2(root->left, root->right);
    
    /*
    std::vector<int> path_l = inorderTraversal(root->left);
    int m_l = path_l.size();
    for(int i = 0; i < m_l; i++) {
        printf("%d ", path_l[i]);
    }
    printf("\n");
    
    std::vector<int> path_r = inorderTraversal1(root->right);
    int m_r = path_r.size();
    for(int i = 0; i < m_r; i++) {
        printf("%d ", path_r[i]);
    }
    printf("\n");
    */
    
    return(symmetric);
}
コード例 #5
0
void traverse2(int previousNode, int currentNode, Location* currentLocation, int* orientation, Location mazeCoords[], int visited[], int dijkstraPath[]) {
	int i, j;
	
	// If graph uninitialised, initialise it
	if (!graphInitialised) {
		for (i = 0; i < 17; i++) {
			for (j = 0; j < 17; j++) {
				graph[i][j] = 0;
			}
		}
		
		graphInitialised = 1;
	}
	
	int adjacentNodes[3];
	findAdjacentNodes(currentNode, *orientation, adjacentNodes);
	
	visited[currentNode] = 1;
	
	/*
	printf("Visited nodes:");
	for (i = 0; i < 17; i++) {
		if (visited[i]) {
			printf(" %d", i);
		}
	}
	printf("\n");
	*/
	graph[0][1] = 1;
	graph[1][0] = 1;
	
	for (i = 0; i < 3; i++) {
		if (adjacentNodes[i] >= 0) {
			graph[currentNode][adjacentNodes[i]] = 1;
			graph[adjacentNodes[i]][currentNode] = 1;
		}
	}
	
	for (i = 0; i < 3; i++) {
		if (adjacentNodes[i] >= 0 && visited[adjacentNodes[i]] == 0) {	
			updateOrientation(orientation, currentNode, adjacentNodes[i]);
			
			printf("Traverse \n");
			printf("Current node: %d \n", currentNode);
			printf("Orientation: %d \n", *orientation);
			printf("Current location: x = %f; y = %f \n", currentLocation->x, currentLocation->y);
			printf("Target location: x = %f; y = %f \n", mazeCoords[adjacentNodes[i]].x, mazeCoords[adjacentNodes[i]].y);
		
			goToPoint(currentLocation, &mazeCoords[adjacentNodes[i]]);
			
			correctLocation(adjacentNodes[i], currentLocation, orientation, mazeCoords);
			
			traverse2(currentNode, adjacentNodes[i], currentLocation, orientation, mazeCoords, visited, dijkstraPath);
		}
	}
	
	updateOrientation(orientation, currentNode, previousNode);
	goToPoint(currentLocation, &mazeCoords[previousNode]);
	correctLocation(previousNode, currentLocation, orientation, mazeCoords);
	
	printf("Current location: x = %f; y = %f \n", currentLocation->x, currentLocation->y);
	
	int explored = 1;
	for (i = 0; i < 17; i++) {
		if (visited[i] == 0) {
			explored = 0;
		}
	}
	
	if (explored) {
		//printgraph();
		dijkstra(0, dijkstraPath);
	}
}
コード例 #6
0
ファイル: func.c プロジェクト: Gonefar/BinaryTree
int get_tree_depth(tree *pTree)
{
	DEPTH = 0;
	traverse2(pTree);
}
コード例 #7
0
ファイル: count4.c プロジェクト: Linn1024/asm
long long traverse()
{
    return traverse2(root);
}