Created
November 5, 2014 21:34
-
-
Save LittleHelicase/e3d1ffd1f00a2a6c8b3e to your computer and use it in GitHub Desktop.
// source http://jsbin.com/wowobu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function ListNode(){ // LinkedListNode var element ; | |
var nextNode; | |
var element; | |
} | |
function LinkedList(){ | |
this.start = null; | |
this.end = null; | |
this.n = 0; | |
this.create = function(){ | |
// Leere Liste initialisieren | |
this.start = null; | |
this.end = null; | |
this.n = 0; | |
}; | |
this.first = function(){ | |
return this.start; | |
}; | |
this.last = function(){ | |
return this.end; | |
}; | |
this.length = function(){ | |
return this.n; | |
}; | |
this.next = function(p){ | |
return p.nextNode; | |
}; | |
this.retrieve = function(p) { | |
return p.element; | |
}; | |
this.insert = function(p, x){ | |
node = new ListNode(); | |
node.element = x; | |
if(p == null){ // p = NIL, Einfügen an erster Position | |
node.nextNode = this.start; | |
this.start = node; | |
}else{ | |
node.nextNode = p.nextNode; | |
p.nextNode = node; | |
} | |
if(p == this.last()){ | |
this.end = node; | |
} | |
this.n = this.n + 1; | |
return node; | |
}; | |
this.predecessor = function(p) { | |
// finde Vorgänger von p | |
currentNode = this.start; | |
while(currentNode) { | |
if(currentNode.nextNode == p) | |
break; | |
currentNode = this.next(currentNode); | |
} | |
return currentNode; | |
}; | |
this.deletePos = function(p) | |
{ | |
pred = this.predecessor(p); | |
if(pred) { | |
pred.nextNode = p.nextNode; | |
} else { | |
this.start = p.nextNode; | |
} | |
if(p == this.last()){ | |
this.end = pred; | |
} | |
this.n = this.n - 1; | |
}; | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function ListNode(){ // LinkedListNode var element ; | |
var nextNode; | |
var element; | |
} | |
function LinkedList(){ | |
this.start = null; | |
this.end = null; | |
this.n = 0; | |
this.create = function(){ | |
// Leere Liste initialisieren | |
this.start = null; | |
this.end = null; | |
this.n = 0; | |
}; | |
this.first = function(){ | |
return this.start; | |
}; | |
this.last = function(){ | |
return this.end; | |
}; | |
this.length = function(){ | |
return this.n; | |
}; | |
this.next = function(p){ | |
return p.nextNode; | |
}; | |
this.retrieve = function(p) { | |
return p.element; | |
}; | |
this.insert = function(p, x){ | |
node = new ListNode(); | |
node.element = x; | |
if(p == null){ // p = NIL, Einfügen an erster Position | |
node.nextNode = this.start; | |
this.start = node; | |
}else{ | |
node.nextNode = p.nextNode; | |
p.nextNode = node; | |
} | |
if(p == this.last()){ | |
this.end = node; | |
} | |
this.n = this.n + 1; | |
return node; | |
}; | |
this.predecessor = function(p) { | |
// finde Vorgänger von p | |
currentNode = this.start; | |
while(currentNode) { | |
if(currentNode.nextNode == p) | |
break; | |
currentNode = this.next(currentNode); | |
} | |
return currentNode; | |
}; | |
this.deletePos = function(p) | |
{ | |
pred = this.predecessor(p); | |
if(pred) { | |
pred.nextNode = p.nextNode; | |
} else { | |
this.start = p.nextNode; | |
} | |
if(p == this.last()){ | |
this.end = pred; | |
} | |
this.n = this.n - 1; | |
}; | |
}</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ListNode(){ // LinkedListNode var element ; | |
var nextNode; | |
var element; | |
} | |
function LinkedList(){ | |
this.start = null; | |
this.end = null; | |
this.n = 0; | |
this.create = function(){ | |
// Leere Liste initialisieren | |
this.start = null; | |
this.end = null; | |
this.n = 0; | |
}; | |
this.first = function(){ | |
return this.start; | |
}; | |
this.last = function(){ | |
return this.end; | |
}; | |
this.length = function(){ | |
return this.n; | |
}; | |
this.next = function(p){ | |
return p.nextNode; | |
}; | |
this.retrieve = function(p) { | |
return p.element; | |
}; | |
this.insert = function(p, x){ | |
node = new ListNode(); | |
node.element = x; | |
if(p == null){ // p = NIL, Einfügen an erster Position | |
node.nextNode = this.start; | |
this.start = node; | |
}else{ | |
node.nextNode = p.nextNode; | |
p.nextNode = node; | |
} | |
if(p == this.last()){ | |
this.end = node; | |
} | |
this.n = this.n + 1; | |
return node; | |
}; | |
this.predecessor = function(p) { | |
// finde Vorgänger von p | |
currentNode = this.start; | |
while(currentNode) { | |
if(currentNode.nextNode == p) | |
break; | |
currentNode = this.next(currentNode); | |
} | |
return currentNode; | |
}; | |
this.deletePos = function(p) | |
{ | |
pred = this.predecessor(p); | |
if(pred) { | |
pred.nextNode = p.nextNode; | |
} else { | |
this.start = p.nextNode; | |
} | |
if(p == this.last()){ | |
this.end = pred; | |
} | |
this.n = this.n - 1; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment