GFreak45
I didnt slap you, i high 5'd your face.
- Reaction score
- 130
ok i had a question, what is better for doubly linked lists?
using next/previous as a normal variable that is just allocated with the struct? or a static array variable?
IE:
or
and how do you reference static array variables inside a struct? is it any different then referencing a method using a function? just structname.variablename?
and for linked lists the best allocation/deallocation method would be this:
using next/previous as a normal variable that is just allocated with the struct? or a static array variable?
IE:
or
JASS:
and how do you reference static array variables inside a struct? is it any different then referencing a method using a function? just structname.variablename?
and for linked lists the best allocation/deallocation method would be this:
JASS:
struct example extends array
integer next = 0
integer previous
static integer array recycleList
static integer listSize
static integer lastRecycled
static method allocate takes nothing returns thistype
local integer i = 0
if (recycleList[0] = 0) then
set listSize = listSize + 1
return listSize
else
set i = recycleList[0]
set example<i>.next = 0
set example<i>.previous = example[0].previous
set example[0].previous = i
set example[example<i>.previous].next = i
set recycleList[0] = recycleList[recycleList[0]]
set recycleList<i> = 0
if recycleList[0] == 0 then
set lastRecycled = 0
endif
return i
endif
endmethod
method deallocate takes integer i returns nothing
set example[example<i>.previous].next = example<i>.next
set example[example<i>.next].previous = example<i>.previous
set example<i>.previous = 0
set example<i>.next = 0
set recycleList[lastRecycled] = i
set recycleList<i> = 0
set lastRecycled = i
endmethod
endstruct</i></i></i></i></i></i></i></i></i></i></i>