(C++ please, 10000Ints.text file will be in a comment below, it won't let me post in description because it is too long.)
|
30 Points |
|
|
20 |
Read Data From File and achieve outcome |
|
5 |
Connect to Text File |
|
5 |
Coding Conventions / Readability of code |
Read data into program from text file 10000Ints.text
below.
Fill a Binary Search Tree with the values from the sample text file included.
Have your program read the information from the text file. Do not copy and paste data into the program.
You can use an IDE or execute in the terminal
How are the value in file ? I have assumed its separated by space Like 10 3 4 5 6 7
#include<iostream>
#include<fstream>
#include <stdlib.h> //srand, rand
#include <time.h>//clock_t, clock, CLOCKS_PER_SEC
#include<iomanip>
using namespace std;
struct node {
int data;
struct node* left;
struct node* right;
};
struct node* newNode(int data) {
struct node* node = new(struct node); // "new" is like "malloc"
node->data = data;
node->left = NULL;
node->right = NULL;
return(node);
}
struct node* insert(struct node* node, int data) {
// 1. If the tree is empty, return a new, single node
if (node == NULL) {
return(newNode(data));
}
else {
// 2. Otherwise, recur down the tree
if (data <= node->data) node->left = insert(node->left, data);
else node->right = insert(node->right, data);
return(node); // return the (unchanged) node pointer
}
}
/*
Given a binary tree, return true if a node
with the target data is found in the tree. Recurs
down the tree, chooses the left or right
branch by comparing the target to each node.
*/
static int lookup(struct node* node, int target) {
// 1. Base case == empty tree
// in that case, the target is not found so return false
if (node == NULL) {
return(false);
}
else {
// 2. see if found here
if (target == node->data) return(true);
else {
// 3. otherwise recur down the correct subtree
if (target < node->data) return(lookup(node->left, target));
else return(lookup(node->right, target));
}
}
}
void inOrder(struct node *root){
if(root!=NULL){
inOrder(root->left);
cout << root->data<<" ";
inOrder(root->right);
}
}
int main() {
struct node *root= NULL;
char val[10];
ifstream fin; //File reader
clock_t start, end;
fin.open("10000Ints.txt");
if (!fin) {
cerr << "Not able to open 10000Ints.txt file" << endl;
return 1;
}
while(fin >> val){
root = insert(root, atoi(val));
}
cout<<"InOrder Traversal of BST is : "<<endl;
inOrder(root);
cout<<endl;
return 0;
}
===============================================================
See Output
Thanks, PLEASE COMMENT if there is any concern.
(C++ please, 10000Ints.text file will be in a comment below, it won't let me post in...
Please Only use C language In this assignment, you have to read a text file (in.txt) that contains a set of words. The first line of the file contains 3 numbers (N, S, D). These numbers represent the sequence of input words in your file. N: represents the number of words to read to build a binary search tree. You have to write a recursive insert code to create and insert these words into the binary search tree. After inserting...
The following code is from a C++ file. What I'm wondering/looking for is if there's another way to insert numbers 1-100 in a random order. I don't think you should need the code for BinarySearchTree.h, but if you do, copy and paste the link below into your browser for it. https://justpaste.it/30xml /* * Create another integer Binary Search Tree. Insert the numbers from 1 to 100 in a random order. * Then search for all 100 numbers in the tree...
(in C) Binry Srch tree problem: 1. Need to read words from a “in” text file and build a binary search tree. (1st line will state number of elements) 2. strcmp() can be used to compare data and decide were to insert a new node. 3. The output should include: -print the tree as in-order traversal. -print the character count in the tree. -Ask user input for a word to search, print an output if either found or not. (typing...
in this coding please add an address for the student to enter... note that this coding use linked list and a file text to store its data ...Please make sure the address will work with all the functions below..to check whether your coding is correct after you finished adding a new dummy student data and its information close the program and reopen it and choose the option 5 ... I've tried adding an address before but an error occurred when...
Please write this in C.
Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...
Overview: file you have to complete is
WordTree.h, WordTree.cpp, main.cpp
Write a program in C++ that reads an input text
file and counts the occurrence of individual words in the file. You
will see a binary tree to keep track of words and their counts.
Project description:
The program should open and read an input file (named
input.txt) in turn, and build a binary search tree
of the words and their counts. The words will be stored in
alphabetical order...
Hello! i need a program in C that uses FILE*! The instructions are below! Please dont copy paste another chegg post! Thank you! Will leave positive review! I need a program that 1) Count all words in a file. A word is any sequence of characters delimited by white space or the end of a sentence, whether or not it is an actual English word. 2)Count all syllables in each word. To make this simple, use the following rules: •Each...
please read directions first. this is supposed to be a hybrid programe add comments please JAVA please add comments Programming Project 1 and Programming Project 2 "Hybrid" Your goal is to write a program that combines the functionality of both Programming Project 1andProgramming Project 2 into a single program. That is, your program should read a file ( Numbers.txt) of numbers of type double that contains some duplicates and is ordered smallest to largest. Your program should ignore the duplicate...
Using C Please comment
Part 1: BST Create a link based Binary Search tree composed of a Node and a Tree struct. You should have a header file, BST.h, with the following: o Node struct containing left, right, and parent pointers, in addition to holding an Data struct value Tree struct containing a pointer to the root of the tree A function declaration for a function that allocates a tree, and initializes the root to NULL o o o A...
Program Description: (C++). Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of characters in the input data file that are not vowels. Your program must do this by providing the following functions : void processFile(ifstream &inFile, string &word, int &wordCount, int &nonVowelCount) ; void...