Example #1
0
void displayPreOrder(node *n) {
    if(n != NULL) {
        printf("%d ", n->data);
        displayPreOrder(n->leftChildNode);
        displayPreOrder(n->rightChildNode);
    }
}
void BST<T1, T2>::displayPreOrder(BST<T1, T2> *node)
{
   if (node != NULL)
   {
      cout << node->mData << "  ";
      displayPreOrder(node->mLeft);		
      displayPreOrder(node->mRight);
   }
}
void BinaryTree<T>::displayPreOrder(TreeNode *nodePtr) const
{
    if (nodePtr)
    {
        cout << nodePtr->value << "\n";
        displayPreOrder(nodePtr->left);
        displayPreOrder(nodePtr->right);
    }
}
Example #4
0
void AvlTree::displayPreOrder(AvlNode *v)
{
	if (v != NULL)
	{
		std::cout << v->key << "  ";
		outputFile << v->key << "  ";
		displayPreOrder(v->left);
		displayPreOrder(v->right);
	}
}
Example #5
0
File: Tree.c Project: goutamdh/Tree
void displayPreOrder(Node *p){

	if(p == NULL){
		return;
	}
	else{
		printf("%d\t", p->data);
		displayPreOrder(p->left);
		displayPreOrder(p->right);
	}

}
Example #6
0
int main(void) {
    int ch, num, num1;
    do {
        printf("\nSelect a choice from the menu below.");
        printf("\n1. Insert a node.");
        printf("\n2. Search for a node.");
        printf("\n3. Delete a node.");
        printf("\n4. Display the Binary Search Tree.");
        printf("\nChoice: ");
        scanf("%d", &ch);
        switch(ch) {
            case 1: printf("\nEnter an element: ");
                    scanf("%d", &num);
                    //printf("YESYES");
                    insertNode(num, &rootNode);
                    break;

            case 2: printf("\nEnter the element to be searched for: ");
                    scanf("%d", &num);
                    searchNode(num, rootNode);
                    break;

            case 3: printf("\nEnter the element to be deleted: ");
                    scanf("%d", &num);
                    deleteNode(num, rootNode);
                    break;

            case 4: printf("\nSelect an order for the elements to be display in.");
                    printf("\n1. Pre-order.");
                    printf("\n2. Post-order.");
                    printf("\n3. In-order.");
                    printf("\nChoice: ");
                    scanf("%d", &num1);
                    switch(num1) {
                        case 1: printf("\nPre-order Display: ");
                                displayPreOrder(rootNode);
                                break;

                        case 2: printf("\nPost-order Display: ");
                                displayPostOrder(rootNode);
                                break;

                        case 3: printf("\nIn-order Display: ");
                                displayInOrder(rootNode);
                                break;

                        default: exit(0);
                    }
                    break;

            default: exit(0);
            }
        printf("\nIf you want to return to the menu, press 1.");
        printf("\nChoice: ");
        scanf("%d", &num);
    } while(num == 1);

    return 0;
}
void BST<T1, T2>::showPreOrder()
{
   displayPreOrder(mRootNode); 
}
Example #8
0
File: Tree.c Project: goutamdh/Tree
int main(void) {
	Node *root = NULL;
	int choice, ele;

	setbuf(stdout, NULL);

	printf("Enter choice : 1 for add Binary Search Tree Iteratively\n2 for add Binary Search Tree Recursively\n3 for display in Pre Order\n4 for display in In Order\n5 for display in Post Order\n6 to count no of BST Nodes\n7 to count Height of BST\n8 to check if it is Strict BST\n9 to check if it is Complete BST\n10 for Binary Search Recursively\n11 for Binary Search Recursively\n12 to add to Binary Tree Iteratively\n13 to add to Binary Tree Recursively\n14 to find Largest element in BT\n15 to count number of nodes in BT\n");

	do{
		printf("Enter choice : ");
		scanf("%d", &choice);

		switch (choice) {
		case 1:
			// Add BST Iterative
			printf("Enter a value\n");
			scanf("%d", &ele);

			addBinarySearchTree(&root, ele);
			break;
		case 2:
			// Add BST Recursively
			printf("Enter a value\n");
			scanf("%d", &ele);

			addBinarySearchTreeRecursively(&root, ele);

			break;
		case 3:
			// Display Pre Order
			displayPreOrder(root);
			printf("\n");

			break;
		case 4:
			// Display In Order
			displayInOrder(root);
			printf("\n");

			break;
		case 5:
			// Display Post Order
			displayPostOrder(root);
			printf("\n");

			break;
		case 6:
			// Count Binary Search Tree Node
			ele = countBinarySearchTreeNodes(root);
			printf("%d\n",ele);

			break;
		case 7:
			// Height Binary Search Tree Node
			ele = heightBinarySearchTree(root);
			printf("%d\n", ele);

			break;
		case 8:
			// Check if Strict Binary Search Tree

			if(isStrictBinarySearchTree(root) == 1){
				printf("Is Strict Binary Search Tree\n");
			}
			else{
				printf("Not a Strict Binary Search Tree\n");
			}

			break;
		case 9:
			// Check if Complete Binary Search Tree

			if(isCompleteBinarySearchTree(root) >= 1){
				printf("Is Strict Binary Search Tree\n");
			}
			else{
				printf("Not a Strict Binary Search Tree\n");
			}

			break;
		case 10:
			// Binary Search Tree Iteratively
			printf("Enter a value to search\n");
			scanf("%d", &ele);

			if(binarySearchIterative(root, ele) == 1){
				printf("Exists\n");
			}
			else{
				printf("Does not exist\n");
			}

			break;
		case 11:
			// Binary Search Tree Recursively
			printf("Enter a value to search\n");
			scanf("%d", &ele);

			if(binarySearchRecursion(root, ele) == 1){
				printf("Exists\n");
			}
			else{
				printf("Does not exist\n");
			}

			break;
		case 12:
			// Add Binary Tree Iteratively

			printf("Enter a value\n");
			scanf("%d", &ele);

			addBinaryTreeIteratively(&root, ele);
			break;
		case 13:
			// Add Binary Tree Recursively

			printf("Enter a value\n");
			scanf("%d", &ele);

			addBinaryTreeRecursively(&root, ele);

			break;
		case 14:
			// Largest Binary Tree
			ele = largestBinaryTree(root);

			printf("Largest element is : %d",ele);

			break;

		case 15:
			// Count No of Binary Tree Nodes
			ele = countBinaryTreeNodes(root);
			printf("%d\n", ele);

			break;

		default:{
			choice = -1;
		}
		}


	}while(choice != -1);


	return EXIT_SUCCESS;
}
Example #9
0
		void displayPreOrder() { displayPreOrder(root); }