abdullahlingga's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 15 (0.05 per day)
- Joined:
- 12-July 12
- Profile Views:
- 532
- Last Active:
Dec 27 2012 04:33 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: USB
Posted 27 Dec 2012
my bad, i think i need to buy again, but thanks.. -
In Topic: Curiosity of a Newbie
Posted 26 Dec 2012
I'm more familiar with java, so what programs do i need to make this? (ex. netbeans for programming, how about for database, and to make it executble if i use java). -
In Topic: finding max and min in a bst problem...
Posted 12 Oct 2012
i see, thank you very much, it works now... -
In Topic: finding max and min in a bst problem...
Posted 12 Oct 2012
it's not working, still giving me the wrong output...
this is my code for my binary tree link
#ifndef BINARYTREELINK_H #define BINARYTREELINK_H #include "BinaryTreeNode.h" #include <iostream> using namespace std; class BinaryTree { public: BinaryTree(); void inorderTraversal(); void preorderTraversal(); void postorderTraversal(); void inorder(BinaryTreeNode* p); void preorder(BinaryTreeNode* p); void postorder(BinaryTreeNode* p); void Min(); void findMin (BinaryTreeNode* p); void Max(); void findMax (BinaryTreeNode* p); void deleteNode(const int &deleteint); void insert(const int & insertint); BinaryTreeNode* deleteFromTree(BinaryTreeNode* p); private: BinaryTreeNode* root; }; BinaryTree::BinaryTree() { root = 0; } void BinaryTree::inorderTraversal() { inorder(root); } void BinaryTree::preorderTraversal() { preorder(root); } void BinaryTree::postorderTraversal() { postorder(root); } void BinaryTree::inorder(BinaryTreeNode* p) { if(p != 0) { inorder(p->getLeft()); cout << p->getData() << " "; inorder(p->getRight()); } } void BinaryTree::preorder(BinaryTreeNode* p) { if(p != 0) { cout << p->getData() << " "; preorder(p->getLeft()); preorder(p->getRight()); } } void BinaryTree::postorder(BinaryTreeNode* p) { if(p != 0) { postorder(p->getLeft()); postorder(p->getRight()); cout << p -> getData() << " "; } } void BinaryTree::Min() { cout << findMin(root); } void BinaryTree::findMin(BinaryTreeNode* p) { if (p != 0) { findMax(p->getLeft()); cout << p->getData(); } } void BinaryTree::Max() { findMax(root); } void BinaryTree::findMax(BinaryTreeNode* p) { if (p != 0) { findMax(p->getRight()); cout << p -> getData(); } } void BinaryTree::deleteNode(const int &deleteint) { BinaryTreeNode* current; BinaryTreeNode* trailCurrent; bool found = false; if(root == NULL) cout << "Cannot delete from the empty tree." << endl; else { current = root; trailCurrent = root; while(current != NULL && !found) { if(current->getData() == deleteint) found = true; else { trailCurrent = current; if(deleteint < current->getData()) current = current->getLeft(); else current = current->getRight(); } } if(current == NULL) cout << "The delete int is not in the list." << endl; else if(found) { if(current == root) root = deleteFromTree(root); else if(trailCurrent->getData() > deleteint) trailCurrent->setLeft(deleteFromTree(trailCurrent->getLeft())); else trailCurrent->setRight(deleteFromTree(trailCurrent->getRight())); } } } void BinaryTree::insert(const int & insertint) { BinaryTreeNode* current; //reference variable to //traverse the tree BinaryTreeNode* trailCurrent = NULL; //reference variable //behind current BinaryTreeNode* newNode; //reference variable to //create the node newNode = new BinaryTreeNode(); newNode->setData(insertint); newNode->setLeft(NULL); newNode->setRight(NULL); if(root == NULL) root = newNode; else { current = root; while(current != NULL) { trailCurrent = current; if(current->getData() > insertint) current = current->getLeft(); else current = current->getRight(); } if(trailCurrent->getData() > insertint) trailCurrent->setLeft(newNode); else trailCurrent->setRight(newNode); } } BinaryTreeNode* BinaryTree::deleteFromTree(BinaryTreeNode* p) { BinaryTreeNode* current; BinaryTreeNode* trailCurrent; if(p == NULL) cout << "Error: The node to be deleted is null." << endl; else if(p->getLeft() == NULL && p->getRight() == NULL) p = NULL; else if(p->getLeft() == NULL) p = p->getRight(); else if(p->getRight() == NULL) p = p->getLeft(); else { current = p->getLeft(); trailCurrent = NULL; while(current->getRight() != NULL) { trailCurrent = current; current = current->getRight(); } p->setData(current->getData()); if(trailCurrent == NULL) p->setLeft(current->getLeft()); else trailCurrent->setRight(current->getLeft()); } return p; } #endif -
In Topic: finding max and min in a bst problem...
Posted 12 Oct 2012
jjl, on 12 October 2012 - 09:19 PM, said:Quote
suppose I insert 3 4 2 1 5 in my binary tree, then if i ask for min the output is 1 2 3 which is wrong
What makes you think that is the wrong output? See what happens when you move your print call before your recursive call to findMin
hmm, i think my condition is wrong, the output must be only 1...
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Click here to e-mail me
Friends
abdullahlingga hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
abdullahlingga has no profile comments yet. Why not say hello?