Exemple #1
0
void printBinaryTree(struct node* binaryTree) {

	if (binaryTree == NULL) return;

	printBinaryTree(binaryTree->left);
	printf("%d : %d\n", binaryTree->level, binaryTree->value);
	printBinaryTree(binaryTree->right);
}
Exemple #2
0
void printBinaryTree(cnode *root)
{
        if (root != NULL)
        {
                printBinaryTree(root -> previous);
                printf("%d ", root -> info);
                printBinaryTree(root -> next);
        }
}
void printBinaryTree(Node* node, int level, char flag, int nodeLen)
{
    if (node == NULL)
    {
        return;
    }
    printBinaryTree(node->right, level + 1, 'v', nodeLen);
    printNodeWithSpecificWidth(node, level, flag, nodeLen);
    printBinaryTree(node->left, level + 1, '^', nodeLen);
}
void TreeHelper<T>::printBinaryTree(const Node * root, size_t indent, size_t inc) {
    if (nullptr == root) {
        return;
    }
    printBinaryTree(root->right_, indent + inc, inc);
    for (size_t i = 0; i < indent; ++i) {
        p(" ");
    }
    pln(root->value_);
    printBinaryTree(root->left_, indent + inc, inc);
}
Exemple #5
0
void printTree(FILE *fp, RootNodeT *np)
{
  
  wrapPrint(fp, "(");
  printBinaryTree(fp, np->child_l);
  wrapPrint(fp, ",");
  printBinaryTree(fp, np->child_m);
  wrapPrint(fp, ",");
  printBinaryTree(fp, np->child_r);
  wrapPrint(fp, ");\n");
  wrapPrint(fp, NULL);
}
Exemple #6
0
void printBinaryTree(bnode *root, int freq)
{
		if (root != NULL)
		{
				printBinaryTree(root -> left, freq);
				if (root -> freq == freq)
						if (strcmp(root -> word, "i") == 0)
								printf("%d %s\n", root -> freq, "I");
						else
								printf("%d %s\n", root -> freq, root -> word);
				printBinaryTree(root -> right, freq);
		}
}
Exemple #7
0
int main()
{
	INTVEC conf = parseInputFile();
	/*
	for(INTVEC_CITER iter = conf.begin(); iter != conf.end(); ++iter)
	{
	std::cout << *iter << " ";
	}
	std::cout << std::endl;
	*/

	std::cout << "Create BinaryTree!" << std::endl;
	pNode pRoot = CreateBinaryTree(conf, 0, conf.size());

	std::cout << "Print BinaryTree!" << std::endl;
	printBinaryTree(pRoot, 0);
	for(std::map<int, INTVEC>::const_iterator mciter = m_tmp.begin(); mciter != m_tmp.end(); ++mciter)
	{
		for(INTVEC_CITER iter = mciter->second.begin(); iter != mciter->second.end(); ++iter)
		{
			std::cout << *iter << " ";
		}
		std::cout << std::endl;
	}
	return 0; 

}
Exemple #8
0
void printBinaryTree(FILE *fp, NodeT *np)
{

  char buf[128];

  if(LEAF(np)) {
    sprintf(buf, "%s:%f", np->name, np->rho);
    wrapPrint(fp, buf);
  }
  else {
    wrapPrint(fp, "(");
    printBinaryTree(fp, np->child_l);
    wrapPrint(fp, ",");
    printBinaryTree(fp, np->child_r);
    sprintf(buf, "):%f", np->rho);
    wrapPrint(fp, buf);
  }

}
Exemple #9
0
int main() {

	int j, t;

	scanf("%d", &t);

	for (int i = 0; i < t; i++) {

		scanf("%d", &j);
		binaryTree = insert(binaryTree, j);
	}

	printBinaryTree(binaryTree);

	system("pause");
	return 0;
}
Exemple #10
0
int main (int argc, char *argv[])
{
		if (argc == 1)
		{
				printf("You must include a filename in the program call.\n");
				exit(1);
		}
		else if (argc > 2)
		{
				printf("Too many arguments.\n");
				exit(1);
		}

		maxSize = 1;
		char *word = NULL;
		char *str = NULL;
		bnode *root = NULL;
		int x;

		str = readFile(argv[1]);
		if(str != NULL)
		{
				const char* limiter = " ,\n\r\t."; //set these as constant characters. Space is included.
				word = strtok(str,limiter);
				if (word == NULL)
				{
						free(str);
						printf("Empty file.\n");
						exit(2);
				}
				root = addNode(root, word); //pass the word in at the root for binary tree.

				while((word = strtok(NULL,limiter)) != NULL)
						root = addNode(root, word);

				free(str);

				//root = rotateTree(root);
				for (x = 1; x <= maxSize; x++) //this is the worst practice and I am so sorry
						printBinaryTree(root, x);
		}

		freeBinaryTree(root);

		return 0;
}
Exemple #11
0
int main(int argc, char *argv [])
{
	int success = SUCCESS;
	stringBinaryTree *test = createStringBinaryTree("C", &success);
	
	addString("AB", test, &success);
	addString("BD", test, &success);
	addString("DA", test, &success);
	addString("EA", test, &success);
	addString("CA", test, &success);
	addString("AA", test, &success);
	
	printBinaryTree(test);
	
	binarySearch("AA", test);
	binarySearch("ZZ", test);
	binarySearch("CB", test);
	binarySearch("CV", test);
	binarySearch("AB", test);
	return 0;
}
void PrettyPrint(Node* root)
{
    int nodeLen = 17; // each node width
    printBinaryTree(root, 0, 'H', nodeLen);
}
Exemple #13
0
int main()
{
        printf("Enter numbers for doubly linked list in sorted order\n");
        int holding = 0;
        char junk = '.';
        junk = getchar();

        if (atoi(&junk) == 0 && junk != '0')
        {
                printf("Null list added, binary tree is null.\n");
                exit(1);
        }

        int x = 1;
        char *build = malloc(sizeof(char) * x);
        char *tmp = '\0';
        build[0] = '\0';
        while (atoi(&junk) != 0 || junk == '0')
        {
                build[x-1] = junk;
                junk = getchar();
                x++;
                tmp = realloc(build, sizeof(char) * x);
                if (tmp != NULL)
                        build = tmp;
                else
                {
                        printf("Out of memory, program exit.");
                        free(build);
                        exit(3);
                }
                build[x-1] = '\0';
        }
        holding = atoi(build);
        free(build);

        cnode *head = malloc(sizeof(cnode));
        head -> info = holding;
        head -> previous = NULL;
        head -> next = NULL;
        cnode *tail = head;

        while (junk == ' ')
        {
                scanf("%d", &holding);
                if (holding < tail -> info)
                {
                        printf("List is out of order, program exit.\n");
                        freeDoublyLinkedList(head, tail);
                        exit(2);
                }
                tail = insertTail(head, tail, holding);
                junk = getchar();
        }

        printf("Doubly Linked List Contents:\n");
        cnode *ptr = head;
        while (ptr != NULL)
        {
                printf("%d ", ptr -> info);
                ptr = ptr -> next;
        }
        printf("\n");

        cnode *root = toBinaryTree(head, tail);

        printf("Binary Search Tree Contents:\n");
        printBinaryTree(root);
        printf("\n");

        freeBinaryTree(root);

        return 0;
}