• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Simple Question on Linked List

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
uh.. dont use the argument "this" because its used for structs and will probably yell at you (should)
 
Maybe check Mag's tutorial about vJASS Efficient Spell Models

[jass=]// You have two integer arrays:
integer array next
integer array prev
// You insert an instance of a missile in the linked list like this:
// We set the next one to this instance
// to 0 because it's going to be at the end // of the list
set next[index] = 0
// We set the one before this to prev[0],
// which represents the last instance in the list.
set prev[index] = prev[0]
// We set the next one to the last one, to this.
set next[prev[0]] = index
// We make this instance the last one.
set prev[0] = index
// You remove an instance of a missile from the linked list like this:
set next[prev[index]] = next[index]
set prev[next[index]] = prev[index]
// You loop over a linked list like this:
// next[0] is the first instance in the list
local integer currentMissile = next[0]
loop
// if the currentMissile is a null instance, then we stop.
exitwhen currentMissile == 0
// go to the next instance
set currentMissile = next[currentMissile]
endloop[/code]

an example of simple linked list
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Yes, I know about his tutorial but it is graveyarded. He used double LL so I tried to make one on my own but I want to check if it is right or wrong. But anyway there is a flaw with Single LL, which is removing a node from it, you will have to cycle through the entire list in order to link the previous node with the next node assuming that you made the last node linked to the first one, so double would be better, I guess.
 
Status
Not open for further replies.
Top