Here's some starter code for you. The starter code includes a class definition for a single Node in a list, and a class that keeps track of an entire list starting with the root.
Exerises problems ask you to start with the list in one state and write code that transforms it into another state. For example, this "problem A" is asking you to write code to remove the first item from a list:
// Problem A// 1 2 3// 2 3var listA =makeList([1,2,3]);console.log(listA.toString());
// example solution for Problem AlistA.root =listA.root.next;
Try to write code to solve these problems:
functionNode(data) {this.data = data;this.next =undefined;}functionLinkedList() {this.root =undefined;}LinkedList.prototype.toString=function() {var current =this.root;var result ="";while (current !==undefined) { result +=" "+current.data; current =current.next; }return result;}// problem 1// 1 3 4// 1 2 3 4var list1 =makeList([1,3,4]);console.log(list1.toString());// your manipulations hereconsole.log(list1.toString());console.log();// problem 2// 1 2 3 4 5 6 7// 1 2 3 4 5 6 7 8var list2 =makeList([1,2,3,4,5,6,7]);console.log(list2.toString());// your manipulations hereconsole.log(list2.toString());console.log();// problem 3// 1 2 3 4 5 6 8// 1 2 3 4 5 6 7 8var list3 =makeList([1,2,3,4,5,6,8]);console.log(list3.toString());// your manipulations hereconsole.log(list3.toString());console.log();// problem 4// 1 2 3// 2 3var list4 =makeList([1,2,3]);console.log(list4.toString());// your manipulations hereconsole.log(list4.toString());console.log();// problem 5// 34 45 78// undefinedvar list5 =makeList([34,45,78]);console.log(list5.toString());// your manipulations herelist5.root =undefined;console.log(list5.toString());console.log();// problem 6// 23 17 8// 23 23 17 17 8 8var list6 =makeList([23,17,8]);console.log(list6.toString());// your manipulations hereconsole.log(list6.toString());console.log();// problem 7// 3 4 5 6// 6 5 4 3var list7 =makeList([3,4,5,6]);console.log(list7.toString());// your manipulations hereconsole.log(list7.toString());console.log();// DO NOT MODIFY!!// Helper functions to set up lists for each problem.functionmakeList(a) {var list =newLinkedList();list.root =newNode(a[0]);var current =list.root;for (var i =1; i <a.length; i++) {current.next =newNode(a[i]); current =current.next; }return list;}