A5(working)

by Ebony McCoy

HTML

<br>
<br/>Enter Content Here:
<input type="textbox" id="content"/>

<input type="button" value="Add Node to List" onclick="addNode()"/>

<br/>




<p id="output"></p>

CSS

var ll = new LinkedList();
function LinkedList() {
  
  this.head = null;
  this.tail = null;
  this.length = 0;
}

function Node(){
  this.content = null;
  this.last = null;
  this.next = null;
  return this;
}

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.last = this.head;
  this.head.next = this.tail;
  this.length = 2;
  return node;
}
else{
   	alert(document.getElementById("output").innerHTML = "This program only calculates a maximum of 2 numeric entries at a time. Please choose an Operation or clear the stack.");
   }

  //this.tail.next = node
  //node.last = this.tail;
 // this.tail = node;
 // this.length++;
 // return node;
};

function addNode() {
  var content = document.getElementById("content").value;
  ll.add(content);
  ll.print();
}
LinkedList.prototype.print = function() {
  if (this.head === null) return "Empty List";
  var display = " ";
  var counter = 0;
  var node = this.head;
  while (node !== null) {
    counter = counter + 1;
    display += "Node # " + counter + " Content: " + node.content + "</br>";
    node = node.next;
    
    
   }
    document.getElementById("output").innerHTML = display;
   
  };
	
	function isNumber() {

    var content = document.getElementById('content').value;
    if (isNaN(content)) {
      document.getElementById("output").value = 'Input must only be a number or an operator (+, -, *, /)';
    }
		else{
		addNode();
		}

}
LinkedList.prototype.addition = function(){
	var x = this.head.content;
  var y = this.tail.content;
  var result = this.head.content + this.tail.content;
  ll = new LinkedList();
  ll.add(result);
}

LinkedList.prototype.subtraction = function(){
	var x = this.head.content;
  var y = this.tail.content;
  var result = this.tail.content - this.head.content;
  ll = new LinkedList();
 ...

JavaScript

var stack = new Stack();

function LinkedList() {
  
  this.head = null;
  this.top = null;
  this.length = 0;
}

 var Node = function(content){
  this.content = content;
  this.last = null;
  this.next = null;
  return this;
}

this.prototype.push = function (content){
if(this.head == null){
    	this.head = new Node(content);
      this.top = this.head;
      return this;
    }
  //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.last = this.head;
//  this.head.next = this.tail;
//  this.length = 2;
//  return node;
//}
//else{
   	//alert(document.getElementById("output").innerHTML = "This program only calculates a maximum of 2 numeric entries at a time. Please choose an Operation or clear the stack.");
  // }

  //this.tail.next = node
  //node.last = this.tail;
 // this.tail = node;
 // this.length++;
 // return node;
//};

//function addNode() {
//  var content = document.getElementById("content").value;
 // ll.add(content);
  //ll.print();
//}
var addedNode = new Node(_content);
    addedNode.last = this.top;
    this.top.next = addedNode;
    this.top = addedNode;
    return this;
		}
//LinkedList.prototype.print = function() {
  //if (this.head === null) return "Empty List";
//  var display = " ";
  //var counter = 0;
 // var node = this.head;
 // while (node !== null) {
  //  counter = counter + 1;
    //display += "Node # " + counter + " Content: " + node.content + "</br>";
    //node = node.next;
    this.prototype.pop = function() {
    if (this.head == null) {
      alert("Stack is Empty");
      return null;
    }
    
    if (this.head == this.top) {
			this.head = null;
    	return this.top.content;
    }
    
  
   var a = this.top.content;
    this.top = this.top.last;
    this.top.next = null;
  
    return a;
  }

  this.toString = function() {
    var str = "";
    var node =...