I'm implementing a generi method that's supposed to traverse a binary tree in PostOrder but when I attempt to use it, the Iterator doesn't work as It should when I attempt to use ot on a Binary Tree, can anyone spot my mistake in the code? Thanks. The method makes use of a generic POIterator class which implements a generic Iterator<T> here's th POIterator class public class POIterator<T> implements Iterator<T>{ Deque<BNode<E>>someStack = new LinkedList<BNNode<E>>(); BNode<E> position; public T next(){ position = position.pop(); if(!position.hasLeftNode()) return position.getInfo(); else{ position = position.getLeftNode(); somestack.push(position);} next();//recurisive call position = position.pop(); if(!position.hasRightNode()) next();//recursive call }//end of …

Member Avatar
Member Avatar
+0 forum 2

I need help in building a binary tree and putting integers in it. I need to write an add method in my MyArrayBinaryTree class (that extends ArrayBinaryTree) that allows me to place the element to be added in the very next available slot in the array. I also need to write its constructors since MyArrayBinaryTree is derived from ArrayBinaryTree, and therefore inherits all of its methods (except the constructors). I cannot put my add method in ArrayBinaryTree class because that is the implementation of the ADT. How does the add method look like and what constructors do I have to …

Member Avatar
Member Avatar
+0 forum 2

I am having a few compiling errors due to the syntax confusion on some the functions, Im confused to what im doing wrong, I know its a simple solution I've just been looking at this for hours and cant figure it out. //Header File #ifndef BST_H #define BST_H #include <iostream> namespace cop4530 { template <typename T> class BST { public: BST(int th=default_threshold_value);//Constructor BST(const string, int th=default_threshold_value); BST(const BST&); ~BST(); void buildFromInputString(const string input); const BST & operator= (const BST &); bool empty(); void printInOrder() const; void printLevelOrder() const; int numOfNodes() const; int height() const; void makeEmpty(); void insert(const T& v); …

Member Avatar
Member Avatar
+0 forum 2

So Im creating Simple Binary Tree, not BST. Im having problem in deletewith 2 child. Method for deletion is DELETE WITH COPYING. After deleteing, when I traverse the tree, it shows run time error, **Unhandled exception at 0x008B5853 in binarytree.exe: 0xC0000005: Access violation reading location 0xFEEEFEEE.** Here is the function: void BinaryTree<mytype>::deletewithTwoChild(BTNode<mytype> *temp) //temp is the node which is to be deleted. { BTNode<mytype> *father = findfather(temp, root); //found address of father of temp node & stored it in pointer BTNode<mytype> *leaf = temp; //created a copy of temp node /////CASE 1 (for predecessor) if(temp==root || father->left==temp) //if father is …

Member Avatar
Member Avatar
+0 forum 8

This is my code for adding and removing from a binary tree but apparently its not complete can anyone tell me what to do to make it complete tree? [CODE] public void add(IBinaryTreeNode<E> e) { if (getRoot() == null) { setRoot(e); } else { //SAME HERE IBinaryTreeNode<E> node = getLastNode(); node.setRightChild(e); e.setParent(node); } setLastNode(e); setSize(getSize() + 1); } @Override public IBinaryTreeNode<E> remove() { IBinaryTreeNode<E> node = getLastNode(); if (!node.equals(getRoot())) { //IM SURE SOMETHING WRONG HERE node.getParent().setRightChild(null); setLastNode(node.getParent()); } else { setLastNode(null); setRoot(null); } node.setParent(null); setSize(getSize() - 1); return node; }[/CODE]

Member Avatar
Member Avatar
+0 forum 3

I am stuck, I know how binary tree works, but I don't have any clue how to add data recursively in a binary tree. The user needs to enter a formula with logical operators. If the user presses to a button e.g NOT(unary operator), then it should display at follow : NOT(...) Then instead of the 3 dots the user can enter manually a letter "b" or another operator by pressing any of the button (e.g AND) which is a binary operator. NOT ( (...) AND (...)), then again the user have the choice to enter a letter or to …

Member Avatar
Member Avatar
+0 forum 5

I am trying to build a binary tree in c++ when I compile I get an error that says: [code] Undefined first referenced symbol in file Btree::destroy_tree(node*) /var/tmp//cc1bssfK.o Btree::remove(int, node*) /var/tmp//cc1bssfK.o Btree::insert(int, node*) /var/tmp//cc1bssfK.o Btree::search(int, node*) /var/tmp//cc1bssfK.o Btree::~Btree() /var/tmp//cc1bssfK.o Btree::Btree() /var/tmp//cc1bssfK.o ld: fatal: Symbol referencing errors. No output written to a.out collect2: ld returned 1 exit status [/code] Any suggestions would be great thanks!

Member Avatar
Member Avatar
+0 forum 1

hello, i m a student and working on a mlm project and want to generate a binary tree. please can any one send me the code for it in C#.net please help me.

Member Avatar
Member Avatar
+0 forum 3

I''ve got a struct like this: struct Node { int n; Node *left; Node *right; } I build up a binary tree from this struct. Now, how can i save the binary tree onto the hard disk, and how can i rebuild it from the hard disk ?

Member Avatar
Member Avatar
+0 forum 8

Hello I'm coding an algorithm based on genetic programming with tree structures in C. I implemented tree structure using recursive structure pointers **The traditional way** [CODE] struct tree { int val; tree *left; tree *right; }; tree a[10]; tree b[20]; void main() { generate (); // this generates me 10 random trees and places them in a b[0] = a[0]; // copies val, left and right correspondingly // though b[0].left and a[0].left are stored separately, both point to the same location // if i change a[0].left->val , it correspondingly reflects when i access b[0].left-> // This is not intended for …

Member Avatar
Member Avatar
+0 forum 3

i need to make a program that implements a heapsort using a binary tree. i understand the algorithm for how to do the sort, and i understand how it would be done using an array, but for my class i have to use a binary tree. The problem i am having is that nodes dont have a getParent, and although the finding a parents "index" in the tree is either n-1/2 or n-2/2, i dont understand how to get the index of the current node. for example in a binary tree that has 10 nodes, with the index at the …

Member Avatar
+0 forum 0

Hello :) I'm creating a license plate recognition system for my coursework at University. We need to use Binary trees, which I've done but the information needs to be stored in a file to read and write to. I've created some text files with XML tags in for Cars, Lorries, Buses and Motorbikes and I've written some of the code below, but the "File to open" bit my tutor helped me with. When I run the program, it says "File to open" and I'm not sure what I need to do? Would anyone be able to help me? [CODE]int _tmain(int …

Member Avatar
Member Avatar
+0 forum 8

Hello, I've been looking at this problem for a few hours, and I can't figure it out. We had to test this code and fix it if we find errors (it's a splay tree): [CODE] public class SplayBST { Node root; int count; int level = 0; public SplayBST() { root = null; count = 0; } //assumes no duplicates public void add(String x) { root = splayInsert(root, x); count++; } // moves node containing x to the root public Node search(String x) { System.out.println("Search"); return root = splaySearch(root, x); } Node splayInsert(Node h, String x) { if (h == …

Member Avatar
Member Avatar
+0 forum 2

hi, i'm currently learning C on my own. i explicitly made a binary tree just to see if my postorder procedure works. i have no idea why but at the end of running the program, before it does the last procedure, this appears: [IMG]http://i56.tinypic.com/2nb52xx.jpg[/IMG] everything else works fine. i know it must be the [B]postorder[/B] which has the problem but i have no idea why. please help me. below is my code: [CODE]#include <stdio.h> #include<stdlib.h> #include<conio.h> struct node { struct node *LeftNode; char data; struct node *RightNode; }; node *makeNode(char c); void visit(struct node *N); void postorder (struct node *N); …

Member Avatar
Member Avatar
+0 forum 5

Hi, My program is supposed to implement a binary tree with an insert, remove, copy, pre-order, post-order and in-order functions. Problem is that my code compiles but doesn't work correctly. When I try to insert more than one node/child node the program crashes/freezes. Could someone help me out. Thanks. header file: [B]brownt7.h[/B] [CODE] #ifndef _BROWNT7_H #define _BROWNT7_H #include <iostream> typedef signed int ElementF10; struct BSTNode; typedef BSTNode *BSTPtr; struct BSTNode { ElementF10 element;//holds the value to be added BSTPtr left; BSTPtr right; }; //defining class with name QueueF10 class BSTF10 { public: BSTF10( ); BSTF10( const BSTF10 & ); ~BSTF10( …

Member Avatar
+0 forum 0

I recently had an assignment for an advanced coding class where I was to create a Binary tree from inorder and preorder traversals. I first started out by creating my ADT for binary trees and working with that to create a new tree. The way I worked it was that I started by storing inorder traversal in an array and preorder in a queue and then I went through dividing the array into smaller arrays and passing it to the function again, recursively. The base case was when there was only one element in the array, i.e. a leaf. and …

Member Avatar
Member Avatar
+0 forum 5

To begin, we were asked to make a TREE... It says that we should traverse the left subtree of the ROOT/NODE in postorder and then make a copy of it... Next is to traverse the right subtree of the ROOT/NODE in postorder and then make a copy of it... Lastly, we should attach those copies of subtrees and display the tree... So far i have this code: THE BINARY TREE CLASS [CODE]class BinaryTree{ BTNode root; BinaryTree(){ } BinaryTree(BTNode n){ root = n; } BinaryTree(BTNode n, BTNode left, BTNode right){ root = n; root.left = left; root.right = right; } /* …

Member Avatar
Member Avatar
+0 forum 3

The End.