Created
November 5, 2014 21:01
-
-
Save LittleHelicase/4e7828ac8cced22a0777 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/jewoda
This file contains hidden or 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"> | |
// Einfach verkettete Liste | |
// wie in den Vorlesungsfolien, es wird nur null verwendet, anstelle von NIL, weil Javascript das so will. | |
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; | |
}; | |
this.predecessor = function(p) { | |
// finde Vorgänger von p | |
currentNode = this.start; | |
while(currentNode) { | |
if(currentNode.nextNode == p) | |
break; | |
currentNode = 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">// Einfach verkettete Liste | |
// wie in den Vorlesungsfolien, es wird nur null verwendet, anstelle von NIL, weil Javascript das so will. | |
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; | |
}; | |
this.predecessor = function(p) { | |
// finde Vorgänger von p | |
currentNode = this.start; | |
while(currentNode) { | |
if(currentNode.nextNode == p) | |
break; | |
currentNode = 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 hidden or 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
// Einfach verkettete Liste | |
// wie in den Vorlesungsfolien, es wird nur null verwendet, anstelle von NIL, weil Javascript das so will. | |
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; | |
}; | |
this.predecessor = function(p) { | |
// finde Vorgänger von p | |
currentNode = this.start; | |
while(currentNode) { | |
if(currentNode.nextNode == p) | |
break; | |
currentNode = 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