Sale!

CS 122 Computer Science II Program 5 solved

Original price was: $35.00.Current price is: $35.00. $17.50

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

Create a directory called “PG5” at the top level of your CS122-01-12F folder. Put all the files
pertaining to this assignment in PG5. Place a file called “DONE” in this folder when you have
completed this project.
This program deals with writing recursive methods. In principle, your code in this project can be
quite short. You must make the following classes.
public class LinkedListNode {
public int getInt (); //returns the integer stored in a node
public LinkedListNode getNext (); //gets the pointer to the next node
}
public class LinkedList {
public LinkedList (); //creates an empty linked list (constructor)
public LinkedListNode getHead (); //gets the first node
public int getSum(); //returns the sum of all the elements
public int getMax(); //returns the maximum of all the elements
public LinkedListNode smallest(); //returns the smallest-valued node
public LinkedListNode largest(); //returns the largest-valued node
public void addfront (int i);//adds a node with given value to front of
list
public void Delete (int i);//deletes all nodes with given value from list
void printforward ();//prints the list in forward order
void printbackward ();//prints the list in backward order
}
These classes must contain all the methods seen here. You are to supply all the code for the
methods. You are free to add other methods if you wish. You should add (private) data
elements as well. However, your code must contain no loops of any kind. Any repeated work
MUST be accomplished through recursion.
I don’t want you to hand in a main class. I will supply main. You just have to write everything
else. (You should probably write a main class for testing, but remove it when you turn it in.)
Your final submitted program should only print within the two print methods. Any other
printing that needs to be done, I will do in main.
Handle the following error conditions in this way:
The sum of an empty list is zero.
The maximum of an empty list is zero.
The smallest and largest nodes of an empty list are null.
The head of an empty list is null.
getNext on the last element of a list should return null.
Deleting from or printing an empty list should do nothing.