Thread: LinkedList
View Single Post
Old 12-08-2008, 10:55 PM   #15
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)


Originally Posted by C2H3NaO2
I would put it all into a textmacro. This would give you (and other users you don't know) the ability to create different Lists with different types.
In most cases only having integer lists is enough, but sometimes you have to create a own structs only for storing a string or something like that.

I would have to argue against you here, and say that the majority (if not all) of the time, structs will be stored in the lists. Even if someone wants to store arbitrary values in a list, it makes no sense to duplicate this system for every new type when one can just create a struct which requires less lines and when it is in-lined (vex's map optimizer), provides the same efficiency.

Originally Posted by C2H3NaO2
In my opinion there also belongs pushfront, pushback, popfront and popback (yeah i like the c++ names) methods in the main list struct that ALWAYS works.
pushFront == Link.create()
pushBack == Link.createLast()
popFront == set data = ; call list.front.destroy()
popBack == set data = ; call list.last.destroy()

Originally Posted by C2H3NaO2
btw: In my opinion you should save the size in a integer in the struct List. It would be much faster.
This was probably one of the ideas I was contemplating the most. I thought about it but decided to scrap it. My reasons are:
  1. Then I need to add 1 and subtract 1 every time the list is changed (over-time, becomes slow especially if you want to sort the list)
  2. How many times do you really need list.size? It makes no sense to do so, other than for personal enjoyment. If you need to loop through the list, it's much easier and efficient to do.
    Collapse JASS:
    set tempLink = list.first
        exitwhen tempLink == 0
        call DoStuffWithLink(tempLink)
        set tempLink =
Same principle to check if the list is empty: if list.first == 0 then //empty It was just a feature that I felt would not be used enough to compensate for the slow-downs caused by adding and removing links.

I do thank you for your criticism though; and your english was fine.

edit: Another update. Changed names of methods; that is all.
Ammorth is offline   Reply With Quote