write a binary search tree program - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

write a binary search tree program

vinnythepuvinnythepu Posts: 2Member

You need to implement a binary search tree. Each node contains a student ID (Integer) which is the key value, a student name (String), a book ordered list (Linked list), a balance (Float or Double), a left pointer and a right pointer. Your program will read input from a file (one record per line) and the file name must be a command line argument to the program (50 points penalty).

Requirements:

Insert [student ID] [student name] [book name] [number of copy of the book] [price per copy]

- If the student ID is not in the tree, create a new node with the student ID and insert to the tree.
- If the student ID is in the tree and the book name is in his/her book ordered list, change the number of the copy of the book and his/her balance.
- If only student ID is in the tree, add the book into the front of his/her book ordered list and change his/her balance.

ex) I 12345 james Thinking in C 1 20.00
I 12345 james Thinking in Java 4 40.00


Delete [student ID] [book name] [number of copy of the book]

- Find the student ID in the tree and change his/her book ordered list and balance. Then, if the student's balance is zero ( this means no book is ordered), remove the node from the tree.
- If the number of copy of the book is larger than in his/her book ordered list, cancel this transaction and print a proper message.
- If the student ID or the book name is not in the tree or in his/her book ordered list, print a proper message.

ex) D 12345 Thinking in Java 1


Display

- Print each node with a student ID, a student name, a book ordered list and a balance by inorder traversal.
- A book ordered list should be printed from the front (head).
- This function should be iterative, not recursive (15 points penalty).

ex) 12345 Tiako
Thinking in Java 3 40.00
Thinking in C 1 20.00
Balance: $140.00




Comments

Sign In or Register to comment.