- Joined
- Apr 24, 2012
- Messages
- 5,113
So, I was trying to code a Dequeue and I can't think of how to do it. Then I came up to this idea:
Demo code:
Its not a Dequeue(i guess)
Its a double-ended structure,both grows in each end(Front and Back).
It works like a Stack,which retrieves the last node to the first node or first node to the last node operation.
Does anybody knows this data structure?
JASS:
module UnknownFields
readonly thistype front
readonly thistype back
endmodule
module UnknownPushFront
implement UnknownFields
static method pushFront takes thistype node returns nothing
set thistype(0).front.back = node
set node.front = thistype(0).front
set thistype(0).front = node
endmethod
endmodule
module UnknownPushBack
implement UnknownFields
static method pushBack takes thistype node returns nothing
set thistype(0).back.front = node
set node.back = thistype(0).back
set thistype(0).back = node
endmethod
endmodule
module UnknownPopFront
implement UnknownFields
static method popFront takes nothing returns thistype
local thistype node = thistype(0).front
set thistype(0).front = node.front
set thistype(0).front.back = 0
return node
endmethod
endmodule
module UnknownPopBack
implement UnknownFields
static method popBack takes nothing returns thistype
local thistype node = thistype(0).back
set thistype(0).back = node.back
set thistype(0).back.front = 0
return node
endmethod
endmodule
module UnknownPush
implement UnknownPushFront
implement UnknownPushBack
endmodule
module UnknownPop
implement UnknownPopFront
implement UnknownPopBack
endmodule
module UnknownClear
implement UnknownFields
static method clear takes nothing returns nothing
set thistype(0).front = 0
set thistype(0).back = 0
endmethod
endmodule
module Unknown
implement UnknownPush
implement UnknownPop
implement UnknownClear
endmodule
Demo code:
JASS:
struct Hello extends array
implement Unknown
static method onInit takes nothing returns nothing
local thistype i = 1
call pushFront(i)
set i = i + 1
call pushFront(i)
set i = i + 1
call pushFront(i)
set i = i + 1
call pushFront(i)
set i = i + 1
call pushBack(i)
set i = i + 1
call pushBack(i)
set i = i + 1
call pushBack(i)
set i = i + 1
call pushBack(i)
call BJDebugMsg(I2S(popFront()))
call BJDebugMsg(I2S(popFront()))
call BJDebugMsg(I2S(popFront()))
call BJDebugMsg(I2S(popFront()))
call BJDebugMsg(I2S(popBack()))
call BJDebugMsg(I2S(popBack()))
call BJDebugMsg(I2S(popBack()))
call BJDebugMsg(I2S(popBack()))
endmethod
endstruct
Its a double-ended structure,both grows in each end(Front and Back).
It works like a Stack,which retrieves the last node to the first node or first node to the last node operation.
Does anybody knows this data structure?
Last edited: