Question: Topic: AVL Trees I need a JAVA program that reads from a text file that contains some random isbn numbers(numbers only) and book title. We

Topic: AVL Trees

I need a JAVA program that reads from a text file that contains some random isbn numbers(numbers only) and book title. We then create 'Book' objects with that isbn and title in it. and also create an AVLNode from the isbn. At each and every insert we must build a Binary Search Tree and also check if it is balanced or not, if it is not, then use the rotate function and print out the isbn that is inserted and what rotation was used.

Report each imbalance detection and the node where it occurred; and output the message:

Output:

Imbalance occurred at inserting ISBN 12345; fixed in Left-Right Rotation

Imbalance occurred at inserting ISBN 87654; fixed in Left Rotation

Imbalance occurred at inserting ISBN 974321; fixed in Right-Left Rotation

class AVLNode { int key; (ISBN number) Book value; //create a class representing a book with minimum attributes int height; AVLNode leftPtr; AVLNode rightPtr; } }

void rotate(Node current){ Node child = current.left; // current.right if other way current.left = child.right; // current.right = current.left if other way child.right = current; // current.left = current if other way

child.height = child.updateHeight(); current.height = current.updateHeight();

current = child; }

//Left Double rotation

void leftDoubleRotation(Node current) {

rotation(current.right, RIGHT); rotation(current, LEFT);

}

sample.txt

2837462816 BookTitle1

2132638112 BookTitle2

738456362 BookTitle3

Treat the isbn numbers as an integer inputs and insert those integers as binary search tree.

I'm also fine if you want to write it in C++

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!