Thread: LinkedList
View Single Post
Old 12-05-2008, 02:26 PM   #5
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

Quote:
Originally Posted by Anitarf
...ok, I really don't have that much to say, it's pretty neat. There's just a bit many methods, I don't particularly like all those that treat the list as an array by either taking or returning indexes, if you think they're justified that raises the question why doesn't your stack resource submission have them as well. Also, I think you should ditch the getElement method, users shouldn't be able to get a random element from the list like that because all they can do with it is break stuff, since all methods are pretty much meant to be called only on first elements, so getting another list element isn't only dangerous but pretty useless.

Originally, everything was private and the user was only able to access information from the header node. Although this is great for keeping everything from being tampered with, when it came time to use it, I found I was wanting to loop through the list on my own and do some comparisons and such. The problem with that is doing:

Collapse JASS:
local integer i = 0
loop
    exitwhen i >= list.size
    doSomethingWith( list[i] )
    ...
    set i = i + 1
endloop

would have huge performance issues (due to starting at the front for each access), vs:

Collapse JASS:
local integer i = 0
local LinkedList temp = list.next // first slot
loop
    exitwhen i >= list.size
    doSomethingWith( temp )
    ...
    set temp = temp.next
    set i = i + 1
endloop

here, one can traverse the list with O(n) time vs O(n*n!). Maybe ill make it readonly... I'll take a look at it when I get a chance (currently running).

I'll also address the rest of your comments later (I don't mind being nit-picked, anything to make it better).
__________________
Ammorth is offline   Reply With Quote