write code in java. 1) write a method that inserts a node at the beginningof the
ID: 3612818 • Letter: W
Question
write code in java. 1) write a method that inserts a node at the beginningof the linked list and a method that deletes the first node of thelinked list. 2) Repeat a part a but this time perform the insertion anddeletion at the end of the list instead of at the beginning. 3) repeat part b but this time assume that the list has tailrefrence as well as a head reference. write code in java. 1) write a method that inserts a node at the beginningof the linked list and a method that deletes the first node of thelinked list. 2) Repeat a part a but this time perform the insertion anddeletion at the end of the list instead of at the beginning. 3) repeat part b but this time assume that the list has tailrefrence as well as a head reference.Explanation / Answer
class LinkedList{private Node head;private int listCount;public LinkedList(){// this is an empty list, so the reference to the head node// is set to a new node with no datahead = new Node(null);listCount = 0;}public void add_a(Object data)// post: appends the specified element to the end of this list.{Node temp = new Node(data);temp.setNext(head);head=temp;listCount++;// increment the number of elements variable}public boolean remove_a()// post: removes the element at the specified position in this list.{int index=1;// if the index is out of range, exitif(index < 1 || index > size())return false;Node current = head;for(int i = 1; i size())return false;Node current = head;for(int i = 1; i size())return false;current = head;for(int i = 1; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.