JSFiddle - React, Tailwind, and code Playground
by mecfall2018
HTML
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script type="text/javascript">
var list = null;
function createList() {
var value = document.getElementById("LinkName").value;
list = new List(value);
document.getElementById("demo").innerHTML = list.print();
}
function addNode() {
var value = document.getElementById("LinkName").value;
list.addNode(value,list.last);
document.getElementById("demo").innerHTML = list.print();
}
function Node(_value, _last) {
// implement of a Doubly Linked List
this.value = _value; // Where the value is stored
this.last = _last; // click to the previous link
this.next = null; // click to the next link
return this; // displays the created node
}
Node.prototype.asString = function () {
return "=>Node " + this.value + "<br/>";
}
function List(_value) { // list with the first link defined
this.length = 1;
this.head = new Node(_value, null);
this.last = this.head; // the head and last are the same.
}
//Function to add node to list (Changed this code)
List.prototype.addNode = function (_value,_last) {
var node = new Node(_value, _last); // create a new node to attach it to the list
if (this.length) { //If list has some node already
this.last.next = node; //Creating next node of current last node of the list
node.last = this.last;
this.last = node; // Creating node as a last node of the list
} else {
this.head = node;
this.last = node;
}
this.length++;
}
List.prototype.print = function () {
var s = "";
var n =...