RB_JSFIDDLE_A4_Attempt2
by Ryan Brown
HTML
<form id="formski">
<input type ="textbox" id="value" value="F" />
<br>
<input type ="button" value="Add Node" onClick="combine();" />
<p id ="grab">
</p>
</form>
CSS
#formski {
font-family: courier new;
width: 15em;
height: 5em;
color: darkblue;
}
JavaScript
var CreateList = function()
{
this.head = 0;
this.tail = 0;
this.length = 0;
var AddNode = function (id, content)
{
this.next = 0;
this.last = 0;
this.id = id;
this.content= content;
};
this.add = function(id, content)
{
if (this.head ==0)
{
this.head = new AddNode(id, content);
this.length++;
return this.head;
}
if (this.tail == 0)
{
this.tail = new AddNode(id, content);
this.head.next = this.tail;
this.tail.last = this.head;
this.length++;
return this.tail;
};
this.tail.next = new AddNode(id, content);
this.tail.next.last = this.tail;
this.tail = this.tail.next;
this.tail.next = 0;
this.length++;
return this.tail;
}
};
CreateList.prototype.length = function ()
{
var L = 0;
var node = this.head;
while (node != 0)
{
L++;
node = node.next;
}
return L;
};
CreateList.prototype.toString = function()
{
var Svalue = 'Linked With ' + this.length + ' nodes <br>';
var node = this.head;
while (node != 0)
{
Svalue += "Node ID: " + node.id + ': Node Value: ' + node.content;
Svalue += "<br>";
node = node.next;
}
return Svalue;
};
var UserList = new CreateList();
UserList.add('1', 'A');
UserList.add('2', 'B');
UserList.add('3', 'C');
UserList.add('4', 'D');
UserList.add('5', 'E');
document.getElementById('grab').innerHTML = UserList.toString();
function combine()
{
var call = UserList.length +1;
var calling = document.getElementById("value").value;
UserList.add(call, calling);
document.getElementById('grab').innerHTML = UserList.toString();
}
/*
function createList()
{
var value = document.getElementById("NewValue").value;
list = new List(value);
...