I NEED THIS CODE TO BE ABLE TO WORK IN JSFIDDLE I NEED THE
* I NEED THIS CODE TO BE ABLE TO WORK IN JSFIDDLE. I NEED THE HTML ASPECT AND THE JAVASCRIPT ASPECT. HERE IS THE LINK TO JSFIDDLE: jsfiddle.net
In Javascript we are going to create a Doubly Linked List. If you know your object oriented code this will be relatively straightforward. Your List will be made up of Nodes. Each node will have the following properties;
Node Properties
id - A simple id for the node itself,
content - A value (String)
next - A pointer to the next node in the List (null for the last node).
last - A pointer to the previous node in the List
List Properties
head - Pointer to the first node in the list
length - Number of nodes in the list
Here is a simple Javascript code that represents the concept using the analogy of a chain and links. It should be a good demonstration for you to use in writing your code. https://jsfiddle.net/reaglin/q46obht6/ This code should help you get started, but you should build your List and Node objects from scratch.
Next - you will populate your list with 5 nodes with content A, B, C, D, E. You will also create a print function for the list that will print the nodes in order. You will need to create some functions to support this functionality.
You will now need to write an interface to allow the user to add nodes to the end of the list. There should be a single text box to enter the Node content, and a button \"Add to List\". When the user adds a node to the list, then you should add the node with the content to the end of the list and print the new list.
Solution
JavScript
var list = null;
function createList() {
var value = document.getElementById(\"LinkName\").value;
list = new List(\"A\");
list.addNode(\"B\");
list.addNode(\"C\");
list.addNode(\"D\");
list.addNode(\"E\");
document.getElementById(\"demo\").innerHTML = list.print();
}
function addNode() {
var value = document.getElementById(\"LinkName\").value;
list.addNode(value);
document.getElementById(\"demo\").innerHTML = list.print();
}
// Define the link object
function Node(_value, _last) {
// This is a possible implementation of a Doubly Linked List
this.value = _value;
this.last = _last;
this.next = null;
return this;
}
Node.prototype.asString = function() {
return \"Node Value:\" + this.value + \"<br/>\";
}
function List(_value) {
this.length = 1;
this.head = new Node(_value, null);
this.last = this.head;
}
List.prototype.addNode = function(_value) {
this.length = this.length+1;
var n = this.head;
while (n.next != null){
n = n.next;
}
n.next = new Node(_value, null); // Pointer TO the head is null
n.next.last = n;
}
List.prototype.print = function() {
var s = \"\";
var n = this.head;
while (n != null){
s += n.asString();
n = n.next;
}
return s;
}
How to use:
Please use this javascript code in the jsfiddle that you have provided.

