Question: WRITE CODE IN JAVASCRIPT! Use the LinkList class: Write removeLast(n) . Delete the last occurrence of an item from a linked list. So if the

WRITE CODE IN JAVASCRIPT!

Use the LinkList class: Write removeLast(n). Delete the last occurrence of an item from a linked list. So if the item is 7 and the list is [1,3,7,4,7,3,7,2], the result is [1,3,7,4,7,3,2]

Use the LinkList: Write removeAll(int n). Deletes all occurrences of an item n from a linked list. So if the item is 7 and the list1 is [1,3,7,4,7,3,2] , then list1.removeAll(7) then list1 becomes [1,3,4,3,2]. Demonstrate by displaying the list contents before and after calling the above methods. Eg:

lst1 [1,3,7,4,7,3,7,2] lst1.removelast(7) [1,3,7,4,7,3,2] lst1.removeall(7) [1,3,4,3,2]

(ATTACH THE removeLast(n) AND removeAll(int n) IN THIS CODE BELOW): class LinkList { private Link first; public LinkList() { first = null; } public boolean isEmpty() { return (first==null); } public void insertFirst(long dd) { Link newLink = new Link(dd); newLink.next = first; first = newLink; } public Link deleteFirst() { Link temp = first; first = first.next; return temp; } public void displayList() { System.out.print("List (first-->last): "); Link current = first; while(current != null) { current.displayLink(); current = current.next; } System.out.println(""); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!