Assignment Asking again for the fourth time can someone plea
Assignment Asking again for the fourth time, can someone please help
Assignment
Asking for the fourth time can someone please help
I need the html separate, I am using an online editor called jsfiddle to demonstrate my work.
In Javascript we are going to create a Doubly Linked List. If you need a little primer on creating objects and classes in Javascript - 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
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
====HTML==================
<html>
<head>
<meta charset=\"utf-8\">
<script src=\"doublyLinkList.js\"></script>
</head>
<body>
Node Value:
<input type=\"text\" name=\"value\" id=\"value\">
<button id=\"addNode\" onclick=\"addToList()\">Add to List
</button>
<p id=\"displayList\">
</p>
</body>
</html>
==============Javascript=================
var list;
var id;
window.onload = function() {
id = 0;
list = new DoublyLinkedList(null, 0, null);
list.add(\"A\");
list.add(\"B\");
list.add(\"C\");
list.add(\"D\");
list.add(\"E\");
}
function Node(id, content, next, last) {
this.id = id;
this.content = content;
this.next = next;
this.last = last;
}
function DoublyLinkedList(head, length, next) {
this.head = head;
this.length = length;
this.next = next;
}
DoublyLinkedList.prototype = {
add: function(content) {
id++;
if (this.head == null) {
this.head = new Node(id, content, null, null);
this.length = 1;
return;
}
var lastNode = this.head;
for (var i = 0; i < this.length - 1; i++) {
lastNode = lastNode.next;
}
var newNode = new Node(id, content, null, lastNode);
lastNode.next = newNode;
this.length++;
},
print: function() {
var result = \"\";
var lastNode = this.head;
for (var i = 0; i < this.length; i++) {
result += lastNode.content + \" \";
lastNode = lastNode.next;
}
document.getElementById(\"displayList\").innerHTML = result;
}
}
function addToList() {
var newNode = document.getElementById(\"value\").value;
list.add(newNode);
list.print();
}

