function Node(element) {
this.element = element;
this.next = null;
}
function NodeList() {
this.head = new Node('head');
this.find = find;
this.fundPrev = fundPrev;
this.findLast = findLast;
this.insert = insert;
this.show = show;
this.remove = remove;
function find(element) {
var _node = this.head;
while (_node.next != null) {
console.log(_node);
if (_node.next.element == element) { return element; }
_node = _node.next;
}
return null;
}
function fundPrev() {
}
function findLast() {
var _node = this.head;
while (_node.next != null)
_node = _node.next;
return _node;
}
function insert(element) {
var _node = new Node(element);
var lastNode = this.findLast();
lastNode.next = _node;
_node.next = null;
}
function show() {
var _node = this.head;
while (_node.next != null) {
console.log(_node.next.element);
_node = _node.next;
}
}
function remove(element) {
var _node = this.head;
var preNode = null;
while (true) {
if (_node.element == 'head' && _node.next == null) return false;
if (_node.next.element == element) {
preNode.next = _node.next.element.next;
return true;
}
if (_node.next == null) return false;
preNode = _node;
}
return false;
}
}
var nl = new NodeList();
nl.insert(1);
nl.insert(2);
nl.insert(3);
console.log(nl.find(2));
nl.show();
console