The purpose of it is to grab a word from a text file, (text1.txt), and then organize the word into a BST, then grab another word, put it in the appropriate node on the BST, and repeat until EOF is reached in text1.txt.... here's the code i have so far...
Code:#include <iostream.h> #include <math.h> #include <stdlib.h> #include <fstream.h> #include <string.h> struct node { char wordFromFile [20]; node *left; node *right; treeNodeNew(char newWord[]); }; struct node* allNode (char data[20]) { struct node* node = new(struct node); node->wordFromFile[20] = data[20]; node->left = NULL; node->right = NULL; return (node); }; struct node* insert(struct node* node, char data[20]) { if (node == NULL) { return(allNode(data)); } else { if (data <= node->wordFromFile) node->left = insert(node->left, data); else node->right = insert(node->right, data); return(node); } } int lookup(struct node* node, int target); int main() { node newNode; char word [20]; ifstream inFile1 ("text1.txt"); if (!inFile1) { cout<<"Error opening file!"<<endl; exit (1); } while (!inFile1.eof()) { inFile1>>word; strcpy (newNode.wordFromFile, word); } inFile1.close(); return 0; } int lookup(struct node* allNode, char target[20]) { if (allNode == NULL) return (false); else { if (target == allNode->wordFromFile) return (true); else { if (target < allNode->wordFromFile) return (lookup(allNode->left, target)); else return (lookup(allNode->right, target)); } } }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.