Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class AVLTree { /* Implements a ALV tree of ints stored in a random access file. Duplicates are recorded by a count field associated

public class AVLTree {

/*

Implements a ALV tree of ints stored in a random access file.

Duplicates are recorded by a count field associated with the int

*/

public static final int CREATE = 0;

public static final int REUSE = 1;

private RandomAccessFile f;

private long root; //the address of the root node in the file

private long free; //the address in the file of the first node in the free list

private class Node {

private long left;

private long right;

private int data;

private int count;

private int height;

private Node(long L, int d, long r) {

//constructor for a new node

}

private Node(long addr) throws IOException {

// constructor for a node that exists and is stored in the file

}

private void writeNode(long addr) throws IOException {

// writes the node to the file at location addr

}

}

public AVLTree(String fname, int mode) throws IOException {

//if mode is CREATE a new empty file is created

//if mode is CREATE and a file with file name fname exists the file with

// fname must be deleted before the new empty file is created

//if mode is REUSE an existing file is used if it exists otherwise a new empty

// file is

}

public void insert(int d) throws IOException {

//insert d into the tree

//if d is in the tree increment the count field associated with d

root = insert(root, d);

}

private long insert(long r, int d) {

return r;

}

public int find(int d) throws IOException {

//if d is in the tree return the value of count associated with d

//otherwise return 0

return 0;

}

public void removeOne(int d) throws IOException {

//remove one copy of d from the tree

//if the copy is the last copy remove d from the tree

//if d is not in the tree the method has no effect

}

public void removeAll(int d) throws IOException {

//remove d from the tree

//if d is not in the tree the method has no effect

}

public void close() {

//close the random access file

//before closing update the values of root and free if necessary

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Identify and define the eight channels of nonverbal communication

Answered: 1 week ago