Created
November 5, 2014 21:34
-
-
Save LittleHelicase/a3e88f67898ce8d58a62 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/cuqure
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 ArrayListe | |
// wie in den Vorlesungsfolien, es wird nur null verwendet, anstelle von NIL, weil Javascript das so will. | |
function ArrayList(){ | |
this.n = null; | |
this.storageArray = null; | |
this.create = function(){ | |
// Javascript kümmert sich darum, dass das Array groß genug ist.... | |
this.storageArray = []; | |
// Die Liste ist anfangs leer | |
this.n = 0; | |
}; | |
this.length = function(){ | |
return this.n; | |
}; | |
this.first = function(){ | |
if(this.n === 0) return null; | |
else return 0; | |
}; | |
this.last = function(){ | |
if(this.n === 0) return null; | |
else return this.n-1; | |
}; | |
this.next = function(p){ | |
if(p === this.last()) | |
return null; | |
else | |
return p + 1; | |
}; | |
this.retrieve = function(p) { | |
return this.storageArray[p]; | |
}; | |
// Hilfsfunktion, die nicht Teil der ADT ist | |
// schiebt alle Elemente hinter p eine Position nach vorne | |
var moveUp = function(L,p) | |
{ | |
for(var j = L.n; j>p; j--) | |
{ | |
L.storageArray[j] = L.storageArray[j-1]; | |
} | |
}; | |
this.insert = function(p, x){ | |
var pos = p+1; | |
if(p === null) | |
pos = 0; | |
moveUp(this,pos); | |
this.storageArray[pos] = x; | |
this.n = this.n + 1; | |
}; | |
this.deletePos = function(p) | |
{ | |
// schiebe alle Element hinter p | |
// eine Position nach vorne | |
for(var j = p; j>this.n; j++) | |
{ | |
this.storageArray[j] = this.storageArray[j+1]; | |
} | |
this.n = this.n - 1; | |
}; | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// Einfach ArrayListe | |
// wie in den Vorlesungsfolien, es wird nur null verwendet, anstelle von NIL, weil Javascript das so will. | |
function ArrayList(){ | |
this.n = null; | |
this.storageArray = null; | |
this.create = function(){ | |
// Javascript kümmert sich darum, dass das Array groß genug ist.... | |
this.storageArray = []; | |
// Die Liste ist anfangs leer | |
this.n = 0; | |
}; | |
this.length = function(){ | |
return this.n; | |
}; | |
this.first = function(){ | |
if(this.n === 0) return null; | |
else return 0; | |
}; | |
this.last = function(){ | |
if(this.n === 0) return null; | |
else return this.n-1; | |
}; | |
this.next = function(p){ | |
if(p === this.last()) | |
return null; | |
else | |
return p + 1; | |
}; | |
this.retrieve = function(p) { | |
return this.storageArray[p]; | |
}; | |
// Hilfsfunktion, die nicht Teil der ADT ist | |
// schiebt alle Elemente hinter p eine Position nach vorne | |
var moveUp = function(L,p) | |
{ | |
for(var j = L.n; j>p; j--) | |
{ | |
L.storageArray[j] = L.storageArray[j-1]; | |
} | |
}; | |
this.insert = function(p, x){ | |
var pos = p+1; | |
if(p === null) | |
pos = 0; | |
moveUp(this,pos); | |
this.storageArray[pos] = x; | |
this.n = this.n + 1; | |
}; | |
this.deletePos = function(p) | |
{ | |
// schiebe alle Element hinter p | |
// eine Position nach vorne | |
for(var j = p; j>this.n; j++) | |
{ | |
this.storageArray[j] = this.storageArray[j+1]; | |
} | |
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 ArrayListe | |
// wie in den Vorlesungsfolien, es wird nur null verwendet, anstelle von NIL, weil Javascript das so will. | |
function ArrayList(){ | |
this.n = null; | |
this.storageArray = null; | |
this.create = function(){ | |
// Javascript kümmert sich darum, dass das Array groß genug ist.... | |
this.storageArray = []; | |
// Die Liste ist anfangs leer | |
this.n = 0; | |
}; | |
this.length = function(){ | |
return this.n; | |
}; | |
this.first = function(){ | |
if(this.n === 0) return null; | |
else return 0; | |
}; | |
this.last = function(){ | |
if(this.n === 0) return null; | |
else return this.n-1; | |
}; | |
this.next = function(p){ | |
if(p === this.last()) | |
return null; | |
else | |
return p + 1; | |
}; | |
this.retrieve = function(p) { | |
return this.storageArray[p]; | |
}; | |
// Hilfsfunktion, die nicht Teil der ADT ist | |
// schiebt alle Elemente hinter p eine Position nach vorne | |
var moveUp = function(L,p) | |
{ | |
for(var j = L.n; j>p; j--) | |
{ | |
L.storageArray[j] = L.storageArray[j-1]; | |
} | |
}; | |
this.insert = function(p, x){ | |
var pos = p+1; | |
if(p === null) | |
pos = 0; | |
moveUp(this,pos); | |
this.storageArray[pos] = x; | |
this.n = this.n + 1; | |
}; | |
this.deletePos = function(p) | |
{ | |
// schiebe alle Element hinter p | |
// eine Position nach vorne | |
for(var j = p; j>this.n; j++) | |
{ | |
this.storageArray[j] = this.storageArray[j+1]; | |
} | |
this.n = this.n - 1; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment