Linked List, create your own code. (Do not use the build in function or classes of Java or from the textbook). Create a LinkedList class: Call the class MyLinkedList, (hint) Create a second class called Node.java and use it, remember in the class I put the Node class inside the LinkedList Class, but you should do it outside. This class should have o Variables you may need for a Node, o (optional) Constructor Your linked list is of an int type. (you may do it as General type as ) For this Linked List you need to have the following methods: add, addAfter, remove, size, contain, toString, compare, addInOrder. This is just a suggestion, if you use Generic type, you must modify this Write a main function or Main class to test all the methods, o Create a 2 linked list and test all your methods. (Including the compare)
Linked List, create your own code. (Do not use the build in function or classes of Java or from the textbook).
Create a LinkedList class: Call the class MyLinkedList,
(hint) Create a second class called Node.java and use it, remember in the class I put the Node class inside the LinkedList Class, but you should do it outside. This class should have
o Variables you may need for a Node,
o (optional) Constructor
Your linked list is of an int type. (you may do it as General type as <E>)
For this Linked List you need to have the following methods:
add, addAfter, remove, size, contain, toString, compare, addInOrder.
This is just a suggestion, if you use Generic type, you must modify this
Write a main function or Main class to test all the methods,
o Create a 2 linked list and test all your methods. (Including the compare)
![Name of
the method
Constructor
add
addAfter
remove
size
contain
toString
compare
Possible* signature of the method
public void add(int element)
public void addAfter(int element, int
afterint)
public void remove(int value)
public int size()
public boolean contains(int value)
public String toString()
public boolean compare(MyLinkedList
otherList)
addinOrder public void addinOrder (int element)
Explanation
Optional
Add the elements to the head of the Linked
List.
This function add value after a specific
value(int), if the value does not exist, then
add it to the tail. If there are multiple
values of specific value, add it after the
very first one
Given a value in int, if the Linked List has it,
delete it (if the linked list has multiple
places the same value, only the first
occurrence needs to be deleted)
returns the size of the linked list, if empty,
return 0
Check if a Linked List has a value if it does,
return true, else False.
ToString method will override ToString
method to return string containing the
Linked List elements (ready to be printed)
compare two linked list to check if they
have the same value.
This function will add the given elements in
order, as you add, it will after largest value
that is smaller than our element.
If the Linked List is empty, or the element
we want to add is smallest, add to head,
If the value is largest, add to the tail.
Example
We have a linked List:
1->2->4->5->4->3,
call addAfter(9, 4) should add
9 after 4, so the Linked List
will look like:
1->2->4->9->5->4->3
1->2->3->1->3 and we try to
delete 3 we should get 1->2-
>1->3
In the following linked list:
1->3->6->8,
contain(2) should return
False and contain(8) should
return true
Ex: A=1->2->3, B=1->3->2
return false
Ex: A=1->2->3, B=1->2->3
return true
Given: 1->5->12->20
If we try to add 6, it should
add It
1->5->6->12->20](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F8e86230f-5cdf-4308-b446-8633bf74e33b%2Fe9bcf124-599d-4160-b124-81e8fd780c71%2Fqsthj_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 5 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)