Question

Write a program to implement a Dictionary of integers which consists of following methods:

- SortedArray(int a) : is a constructor which creates a dictionary of size a.
- void insert(int x) : Inserts element x at its proper position.
o Raise exception Dictionary_Full when dictionary is already full (in case of SortedArray)
o If x already exists, then raise exception Duplicate_Element_Found
- boolean delete(int x) : Deletes element x and returns true if x existed otherwise false.
o If x does not exists, the operation raises the exception Element_not_Found, which handles the exception by returning the predecessor and successor of x if x would have existed in the dictionary.
o If the dictionary is empty, it raises the Dictionary_Empty exception which handles it by returning a message "Dictionary Empty"
- boolean find(int x) : Returns true if x exists otherwise false and raises the exception Element_not_Found.
- void display() : Displays the dictionary's elements in order.
The input for the program must be from the file input.txt. For example, the input.txt might contain the following sequence of operations
I(5) // I for insert
I(7)
I(5)
R(7) // R is used for delete
F(12) // F for find
D // D is used for display
The output should be written in a file output.txt. For example, for the above sequence of inputs, the Dictionary will generate the following output: Inserted Element 5
Inserted Element 7
Inserted Duplicate Element
Element 7 Deleted
5
5
The assignment is divided into following parts:
PART A: Implement the dictionary using a sorted array. Here you will be required to implement find operation using binary search. The class name should be
SortedArrayTable
PART B: Implement the dictionary using a sorted linked list. Here you will be required to implement find operation using only linear search.The class name should be SortedListTable.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class SortedArray {

int[] array;
int size;

public SortedArray(int a)
{
array = new int[a];
size = 0;
}

public void insert(int x)
{
if(find(x))
{
System.out.println("Duplicate Element Found!");
return;
}
if(size == array.length)
{
System.out.println("Dictionary Full!");
return;
}
if(size == 0)
{
array[0] = x;
size++;
return;
}

for(int i = 0; i < size; i++)
if(array[i] > x)
{
int temp = array[i], temp2;
array[i] = x;
for(int j = i; j < size; j++)
{...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Java Programming: Strings, Odd & Even Numbers, Absolute Values
Homework Solution
$25.00
Java
Programming
Computer Science
Odd Numbers
Even Numbers
Integers
Absolute Values
While Loop
IF-Statements
Data Sets
Input
Output
Sum
Functions
Methods
Strings
Lexicography Order
Java Program: Arrays Of Marks
Homework Solution
$30.00
Java
Programming
Codes
Computer Science
Algorithms
Arrays
Marks
Characters
Strings
Integers
Maximum Value
Minimum Value
Difference
Range
Median
Sorting Methods
Boundaries
Statements
Vaariables
Wordlist Generator in Java (Using OOP)
Homework Solution
$125.00
Java
Programming
OOP
Wordlist Generator
Inheritance
Polymorphism
Arrays
String Class Methods
Charlist
Input
Output
Statements
Variables
Loops
Conditions
Matrix Problem in Java
Homework Solution
$13.00
Java
Programming
Coding
Computer Science
Matrix
Diagonals
Input File
Output File
Integers
Loops
Conditions
Statements
Swapping Numbers
Random Values
Variables
Maze Problem in Java
Homework Solution
$50.00
Java
Programming
Codes
Algorithms
Maze Problem
Classes
Constructor
Stack
Positions
Points
Push
Pop
Symbols
Statements
Variables
Rows
Columns
Strings
Integers
Commands
Pseudo-Code
Get help from a qualified tutor
Live Chats