Binary Search Trees
You are given an input ASCII text file containing an arbitrary
number of student records in the following format:
Operation code: 1 character ('I' for insert, 'D' for delete)
Student number: 7 characters
Student last name: 25 characters
Home department: 4 characters
Program: 4 characters
Year: 1 character
Each record is stored as one line in the text file; i.e. there
is a newline character immediately following the
year.
Create a Java program that does the following:
Be sure to use proper headings and fixed-width columns for both
output files. The program will be invoked from the command line as
follows:
java Assign3 input output1 output2
where Assign3 is the name of the file
containing executable bytecode for your program,
input is the name of the input text file,
output1 is the name of the text file
containing node data from the depth-first, in-order tree traversal,
and output2 is the name of the text file
containing node data from the breadth-first traversal. If the
command line arguments are improperly specified, the program should
print out a “usage” message and abort. Be sure that the specified
files can be opened or created.
Create your own input files to test your code. Start with a file
that specifies only insertions of data into the tree. Later, you
should create a second file that also specifies some deletions as
well. An official input file will be made available on D2L; use
this file to create your output files.
Your program must be able to handle deletions from the binary
search tree. For this, your program will need to examine the first
field (the operation code) in each record of the
input file. If it is the character 'D', then delete the node that
matches from the tree. If there is no match, then report the error
to standard output.
You must program all the data structures for this assignment
from scratch; in other words, do not use any classes from the Java
libraries to implement the binary search tree or queue. Also draw a
picture of the binary search tree, as it appears after processing
all the insertions and deletions specified in the input file.
Within each node, only show the data that is used to order the
tree. The picture can be hand drawn, or you may use a graphics
application to create it.
a3input1.txt
I8534534McKay
0251CT 1
I8400342LaPorte
0045JA 1
I8499120Black
0341RST 1
I8400912Green
0045RFM 1
I8422911Johnston
0341RST 1
I8212399Schafer
0251EST 1
I8367091White
0341TXT 1
I8412094Phillips
0251EST 1
I8400001Smith
0251CT 2
I8255999Sykes
0451WET 2
I8300000Walker
0341TXT 1
I8488431Hall
0341RST 1
I8306700Jones
0251CT 2
I8301164Bannister
0251EST 1
I8500453Banks
0251EST 1
I8388231Woods
0251CT 1
I8503881Appleford
0251EST 1
I8322189Hopper
0251CT 1
I8322889Morrison
0045JA 3
I8422991Card
0045JA 2
I8399129Jordan
0334ENT 1
I8300500Last
0251CT 1
I8500000West
0334ENT 1
I8301234Weston
0334ENT 2
I8508883Fisher
0341TXT 1
I8400000Watson
0334ENT 2
I8599999Zot
0451WET 1
I8499341Waters
0341TXT 1
I8500060Watts
0341RST 1
I8322188Newman
0251CT 2
I8399000Doyle
0334ENT 1
a3input2.txt
I8534534McKay
0251CT 1
I8400342LaPorte
0045JA 1
I8499120Black
0341RST 1
I8400912Green
0045RFM 1
I8422911Johnston
0341RST 1
I8212399Schafer
0251EST 1
I8367091White
0341TXT 1
I8412094Phillips
0251EST 1
I8400001Smith
0251CT 2
I8255999Sykes
0451WET 2
I8300000Walker
0341TXT 1
I8488431Hall
0341RST 1
I8306700Jones
0251CT 2
I8301164Bannister
0251EST 1
I8500453Banks
0251EST 1
I8388231Woods
0251CT 1
I8503881Appleford
0251EST 1
I8322189Hopper
0251CT 1
I8322889Morrison
0045JA 3
I8422991Card
0045JA 2
I8399129Jordan
0334ENT 1
I8300500Last
0251CT 1
I8500000West
0334ENT 1
I8301234Weston
0334ENT 2
I8508883Fisher
0341TXT 1
I8400000Watson
0334ENT 2
I8599999Zot
0451WET 1
I8499341Waters
0341TXT 1
I8500060Watts
0341RST 1
I8322188Newman
0251CT 2
I8399000Doyle
0334ENT 1
D8599999Zot
0451WET 1
D8488431Hall
0341RST 1
D8301234Weston
0334ENT 2
D8212399Schafer
0251EST 1
D8534534McKay
0251CT 1
Binary Search Trees You are given an input ASCII text file containing an arbitrary number of student records in the foll
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am