Last active
August 29, 2015 13:58
-
-
Save h0lyalg0rithm/10365543 to your computer and use it in GitHub Desktop.
Lists in Coffeescript
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
class List | |
constructor:()-> | |
@dataStore=[] | |
@pos=0 | |
@listSize = 0 | |
length:()-> | |
@listSize | |
clear:()-> | |
@dataStore = [] | |
@listSize = @pos = 0 | |
toString:()-> | |
@dataStore | |
insert:(element, prev)-> | |
position = @find(prev) | |
if position > -1 | |
@dataStore.splice(position, 0, element) | |
++@listSize | |
return true | |
return false | |
append:(element)-> | |
@dataStore[++@listSize] = element | |
remove:(element)-> | |
position = @find(element) | |
if position > -1 | |
@dataStore.splice(position,1) | |
--@listSize | |
return true | |
return false | |
contains:(element)-> | |
for elem in @dataStore | |
return true if elm == element | |
return false | |
front:()-> | |
@pos = 0 | |
end:()-> | |
@pos = @listSize -1 | |
prev:(func)-> | |
--@pos if @pos > 0 | |
next:(func)-> | |
++@pos if @pos < @listSize - 1 | |
currPos:(func)-> | |
@pos | |
getElement:()-> | |
@dataStore[@pos] | |
find:(element)-> | |
for elem in @dataStore | |
return elem if elem == element | |
return -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment