Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Submission instructions: 1. Write the programs in Java and save them as .java files. Test your programs and fix any compilation errors. 2. Copy and

Submission instructions:

 

1. Write the programs in Java and save them as .java files. Test your programs and fix any compilation errors.

2. Copy and paste your final version of the programs to ONE MS Word document and save it as a .docx file.

3. Please submit both your source codes (.java files) and the Word document to the Blackboard. I will test the programs by using the source codes (.java file) and make comments on the Word document from the Blackboard grading area.

For this project, you will add the following methods to the singly linked list class, see the attached LinkedList.java.

removeAt(int position) removes the node at the specified position, returning the data of the removed node. It throws an IllegalArgument exception if position is invalid

removeAll() removes all nodes in the list.

getNumberOfNodes() returns the number of nodes in the list

equals(SinglyLinkedList list) compares if two lists contain the same nodes in the same order.

reverse() returns a reversed singly linked list.

1. Implement all the above methods with appropriate Javadoc style comments.

2. For each method, be sure to test your work by adding test code to a main method in a test class.

3. Add appropriate Javadoc style comments to the rest of the methods in the LinkedList class.

------------------------------------------------------------------------------------------------ public class LinkedList { private Node head; public LinkedList() { head = null; } public void addFront(int newData) { Node newNode = new Node(newData); newNode.next = head; head = newNode; } public void addEnd(int newData) { Node newNode = new Node(newData); if(head == null) head = newNode; else { Node curNode = head; while(curNode.next!= null) { curNode = curNode.next; } curNode.next = newNode; } } public void addAfter(int newData, int position) { Node newNode = new Node(newData); //validate the position --TODO //move the curNode to that position int cnt = 0; Node curNode = head; while(cnt"); curNode = curNode.next; } System.out.println(); } private class Node { int data; Node next; Node(int d) { data = d; next=null; } // Constructor } public static void main(String[] args) { LinkedList list = new LinkedList(); for(int i = 1; i<10; i++) list.addFront(i); //list.addFront(1); //list.addFront(2); list.displayList(); //list.removeEnd(); list.addAfter(100, -1); list.displayList(); } }

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_2

Step: 3

blur-text-image_3

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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

4. How would you deal with the store manager?

Answered: 1 week ago

Question

3 How supply and demand together determine market equilibrium.

Answered: 1 week ago

Question

1 What demand is and what affects it.

Answered: 1 week ago