Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using java language In this assignment you will implement a few of the methods for a linked list. In this assignment you will implement a

using java language image text in transcribed
image text in transcribed
In this assignment you will implement a few of the methods for a linked list. In this assignment you will implement a few of the methods for a linked list. Your project should include tests on the LList class to demonstrate that everything is working. You can start with the Node and LList classes we designed in lecture. Implement the following methods: public void addFirst(int value) Create a new node, put the value in it, and add it to the head of the list. We did this in class. Write tests for it to ensure that it works. public int size Return the number of nodes in the list. We did this in class. Write tests for it to ensure it works. public int get(int index) Return the value found at the given index, counting from 0. Throw a Banana exception if the index is out of bounds. We did this in class. public void removeFirst Remove the head node. The second node becomes the head. Throw a Banana exception if there is nothing to remove. public String toString Return a string with all the values, each separated by a comma and a space. The format should be identical to the way Array2 worked, except that the elements are in reverse. Return the empty string if the list is empty. public void insert(int index, int value) Insert a new node into the list. Throw a Banana exception if the index is out of bounds. In class, we did a simulation of a linked list. Here's what we came up with: 1. Start at the head of the list. 2. Move down the list until you reach node number (index-1). For example, if you are inserting at node 4, count until you reach node 3. 3. Create the new node and fill in its value. 4. Adjust the pointers so that the new node is in the correct spot. (I'll leave this up to you to figure out.) Write tests to ensure this is working. public void addLast(int value) Add a new node after the last node (end of the list). 1. Walk down the list, stopping at the last node. Hint: the last node isn't pointing to anything. 2. Create the new node and assign its value. 3. Hook the new node in to the list. Also write tests to ensure this is working

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

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions