Question: using java language, i provided some code already In this assignment you will implement a few of the methods for a linked list. Your project


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. public int size) Return the number of nodes in the list. public int get(int index) Return the value found at the given index, counting from 0. public void removeFirst() Remove the head node. The second node becomes the head. public String toString Return a string with all the values, each separated by a comma and a space. public void insert(int index, int value) Insert a new node into the list. Write tests to ensure this is working, public void addLast(int value) Add a new node after the last node (end of the list). public class Node private int value; private Node next; int getValue({ return value; void setValue(int value) { this.value=value; Node getNext() { return next; void setNext (Node n) { next=n; class Llist{ Node head; void add( int value) { Node nn=new Node(value); nn.setNext(head); head=nn; void traverse() { Node curr=head; while(curr !=null) System.out.println(curr.getValue(); curr=curr.getNext(); for (Node curr=head; curr !=null; curr=curr.getNext() System.out.println(curr.getValue(): if( curr!=null) do{ System.out.println(cuur.getValue(); curr=curr.getNext(); }while(curr! =null); class Driver public static void main(String[] args) {}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
