*getting following error. duplicate found Exception in thread "main" java.lang.NullPointerException at binarysearchtree.main(binarysearchtree.java:185) Java Result: 1 here is my code* public class node<T> { public node<T> root ; public T data; public node left; public node right; public node (T newData) { data = newData; left = null; right = null; root=null; } public node () { data = null; left = null; right = null; } public void setData (T newData) { data = newData; } public T getData () { return data; } public void setLeft (node newLeft) { left = newLeft; } public node getLeft () { return …

Member Avatar
Member Avatar
+0 forum 6

As you know how avl should be balanced after deletion of a node, I'll get to point. For starting, Im considering deleteing a node with no children. For Example a Tree: 10 / \ 5 17 / \ / \ 2 9 12 20 \ \ 3 50 Lets say deletevalue(12); Then Tree should be after deletion: 10 / \ 5 17 / \ \ 2 9 20 \ \ 3 50 Now, we see tree is balanced at node 17, because by formula, its Balance Factor = height( left subtree [left tree is null so -1] ) - height …

Member Avatar
Member Avatar
-1 forum 1

Hello again.I recently have been doing a assignment which asks us to write a function to check whether a tree is perfectly balanced.I know the concept of Perfectly balanced tree but I just cant make out how to write this function.Any help in right direction will be highly welcome.

Member Avatar
Member Avatar
+0 forum 7

I am trying to build a binary search tree. The elements in my input file is printing, but with junk. The problem is with the sentinel in the while loop. I'm not sure of what else to try. I've tried: while (infile) while (count != 14 && infile.good()) while (strcmp(Str, sentinel) != 0) But none of those are working. A sample of my input file is: meel meet food copy home link hear seed read twig tree rain quiz push ride meel And my current output file is: copy food€'M hear homeÈ'M link meeth'M push quizp(M rainX(M read@(M ride seedø'M …

Member Avatar
+0 forum 0

i'm working on visual studio 2008. I'm trying use fopen to open txt files and it does not give any errors but its not doing the required task either. i've to submit this project on monday! please help here's part of the code: [CODE]#include <stdio.h> #include<iostream> #include <conio.h> #include <string> #include <stdlib.h> #include<dos.h> using namespace std; FILE *file_ptr; node* treefromfile() { node *ptree=NULL; char word[20],meaning[100],str[120],*i; int flags=0; file_ptr=fopen("C:\Dictionary","r"); if(file_ptr==NULL) ptree=NULL; else { while(!feof(file_ptr)) { i=fgets(str,120,file_ptr); if(i==NULL) break; seperateword(str,word,meaning); if(flags==0) { ptree=maketree(word,meaning); flags=1; } else addword(ptree,word,meaning); }[/CODE]

Member Avatar
Member Avatar
+0 forum 7

I'm working in the confines of a binary search tree and an AVL tree, doing some operations to find different statistics for these trees when given large random values. For instance some of my functions include finding the average leaf node depth, find the shallowest leaf node, etc. My question is what is the best way to go through these trees and calculate such values, noting which level things are found, etc. I was considering a level order traversal but I'm not sure the implementation. Any hints or advice will help, Thanks! Edit: Any tips about keeping a height variable …

Member Avatar
Member Avatar
+0 forum 1

Hi, I wanted to understand a java code that i picked from a website RoseIndian.net. It is about Binary Search three implementation in java. Can someone please explain how the retrieval of the node values [node.value] in the method "[B]printInOrder(Node node){}[/B]" being done, because the node.values are not being stored in an array, so come are they able to retrieve by calling [B]printInOrder(Node node) [/B] [code] public class BinaryTreeExample { public static void main(String[] args) { new BinaryTreeExample().run(); } static class Node { Node left; Node right; int value; public Node(int value) { this.value = value; } } public void …

Member Avatar
Member Avatar
+0 forum 12

Hi, help please! I have a struct containing an array of pointers to structs containing Binary Search Trees with nodes containing structs. ... <*sigh*> I hate C soo much... put work wants it to be in C. I can set the struct of BST's just fine, and keep it around, and I can set the innermost struct values. My problem is keeping those innermost values once I'm outside the function that puts them there. [CODE] void function(Struct struct, int i, int k) { Array array; array = InitArray(); array->key = k; struct->array[i] = &array; } void otherFunction(Struct struct, int i, …

Member Avatar
Member Avatar
+0 forum 1

Hi. I've a BST created for an address book application for my term project. When inserting into the BST, I insert items sorted by their first names in ascending order. The thing is that the user should be able to display the BST in the ascending form of last names & birthdays as well. My solution to that is inserting items from the BST into a new BST in the sorted form of last names in ascending order. Besides that I've no idea about how to sort by birthdays. So I've coded something for sorting by last name. It uses …

Member Avatar
Member Avatar
+0 forum 9

Hi all. As a part of my project I need to get the address book information saved in a .txt file into a Binary Search Tree. The info in the address book is stored like the following: First Name, Last Name, Date of Birth, E-mail, Phone, Address, City, Zipcode So far I coded this: [CODE] do { fgets(temp, 160, pFile); sscanf(temp, "%s %s %s %s %s %s %s %s", newContact.first_name, newContact.last_name, newContact.date_of_birth, newContact.e_mail, newContact.phone, newContact.address, newContact.city, newContact.zipcode); node = insert(newContact, node); } while ( fgets(temp, 160, pFile) != NULL ); [/CODE] It's just the code to retrieve the information as …

Member Avatar
Member Avatar
+0 forum 16

I need help with a program that is supposed to take data on football players from a txt file and place them in a binary search tree then use case statements to t osearch the tree inorder, preorder and postorder recursively here's what i got so far [CODE] /* Bradley Koperski CIS 126 Project 9 */ /* This program reads football statistics of players on the Chicago Bears from a text files and disblay the desired information via a numbered menu system. */ #include<stdio.h> #include<string.h> # define TYPED_ALLOC(type) (type *)malloc(sizeof (type) /* define player structure */ typedef struct player { …

Member Avatar
Member Avatar
+0 forum 1

I am doing a project where i have to insert a list of players and stats into a binary search tree Here is the project description For this final assignment, you will be creating a binary search tree. You will be able to utilize some of your previous assignment code, but this assignment will be somewhat different. The menu options will be as follows: * 1 - List all players stats (in-order) * 2 - List all players stats (pre-order) * 3 - List all players stats (post-order) Each of these options should be recursive functions following the logic and …

Member Avatar
Member Avatar
+0 forum 1

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 am going out of town and don't have access to my professor and / or tutors for the weekend, and we have an assignment involving a BST. I have done all of my insert, remove, and search functions, and went to the tutor about the remaining ones I have, but he is a genius and I don't necessarily "follow" all he is saying all the time. Anyways, I need help with 3 functions, some of which I have actual code for, others the pseudo-code, which I need further assistance on (not asking for code here, just ideas/clarification). Here is …

Member Avatar
Member Avatar
+0 forum 2

//Binary Search Tree Program #include <iostream> #include <cstdlib> using namespace std; class BinarySearchTree { private: struct tree_node { tree_node* left; tree_node* right; int data; }; tree_node* root; public: BinarySearchTree() { root = NULL; } bool isEmpty() const { return root==NULL; } void print_inorder(); void inorder(tree_node*); void print_preorder(); void preorder(tree_node*); void print_postorder(); void postorder(tree_node*); void insert(int); void remove(int); }; // Smaller elements go left // larger elements go right void BinarySearchTree::insert(int d) { tree_node* t = new tree_node; tree_node* parent; t->data = d; t->left = NULL; t->right = NULL; parent = NULL; // is this a new tree? if(isEmpty()) root = …

Member Avatar
Member Avatar
-1 forum 1

The End.