Question
Questions: 1. Run the java files given below (SLL, SLLNode, LinkedListApplication) related to Linked Lists. Compile and run the programs. 2. Warm-up Exercise: Write a
Questions:
1. Run the java files given below (SLL, SLLNode, LinkedListApplication) related to Linked Lists. Compile and run the programs.
2. Warm-up Exercise: Write a method public int length() in the class SLL
3. Add the following methods to the class SLL
(a) public void insertBefore(T newElem, T existingElem) that inserts an element newElem before the element existingElem. If no existingElem exists, then the method prints existingElem does not exist and returns. If more than one instance of exisingElem exists, then the methods inserts before the first instance of existingElem.
For example, suppose your linked list (of integers) is: [ 3 5 4 2 9 ],
Then a call to insertBefore(new Integer(5), new Integer(9)) would result in the following linked list: [ 3 5 4 2 5 9 ]
A call to insertBefore(new Integer(7), new Integer(5)) would result in [ 3 7 5 4 2 5 9 ]
A call to insertBefore(new Integer(8), new Integer(10)) would result in
WARNING: Element 10 does not exist in the linked list. Insertion failed.
(b) Add the following methods with the same methodology as insertBefore:
(i) public void insertAfter(T newElem, T existingElem)
(ii) public void deleteBefore(T elem)
(iii) public void deleteAfter(T elem)
Make sure you test for cases where the list has only one element.
(c) Write a test class to test these methods.
The test data is as follows:
Make a new linked list, called fruitList of strings with the following information:
[Apple, Mango, Banana, Peach, Watermelon]
Now
(a) insert before Apple the word Fruits.
(b) insert before Banana the word Orange
and print the list.
Likewise, do the same for all four methods. Note that deleteBefore and deleteAfter take only one parameter.
4. [Advanced] Write a class SortedSLL
//LinkedListApplication.java
public class LinkedListApplication { public static void main(String[] args) { SLL
//SLL.java
public class SLL
public class SLLNode
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started