Question: I am trying to make a function within the list that deletes the list i made HTML Javascript function LinkedList() { this.head = null; this.tail
I am trying to make a function within the list that deletes the list i made
HTML
Javascript
function LinkedList() { this.head = null; this.tail = null; this.length = 0; }
function Node() { this.next = null; this.prev = null; this.content = null; }
LinkedList.prototype.add = function(_content) { var node = new Node(); node.content = _content;
if (this.head == null) { this.head = node; this.length = 1; return node; }
if (this.tail == null) { this.tail = node; this.tail.prev = this.head; this.head.next = this.tail; this.length = 2; return node; }
this.tail.next = node; node.prev = this.tail; this.tail = node; this.length++; return node; }
LinkedList.prototype.print = function() { if (this.head == null) return "Empty List"; var s = ""; var node = this.head; while (node != null) { s += node.content + " "; node = node.next; } return s; }
function clearScreen(){ document.getElementById("output").innerHTML = ""; }
var aList = new LinkedList();
function createList(){ aList.add("A"); aList.add("B"); aList.add("C"); aList.add("D"); aList.add("E"); document.getElementById("output").innerHTML = aList.print();
}
function addNode() { var c = document.getElementById("v").value; aList.add(c); document.getElementById("output").innerHTML = aList.print(); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
