Post by shadow008 on Apr 3, 2013 21:46:32 GMT -5
Did it. Give me all the prizes.
Made this in about 15 minutes, sorry it's not commented.
If you know what an arraylist or linked sequence is, you stand a chance at understanding what's happening here.
I highly doubt this is a good way of going about making new memory on the fly, but hell, it's the only way I've ever seen it in this language.
Questions? Comments? Don't understand the significance? Drop a reply.
Happy coding ;D
Made this in about 15 minutes, sorry it's not commented.
If you know what an arraylist or linked sequence is, you stand a chance at understanding what's happening here.
resizeText(80,45)
dim &x() as integer, &y() as integer
dim size as integer = 5, size2 = 3
dim i
function &reSize(&in() as integer, &size as integer)()
dim &temp() as integer
dim i
alloc temp, size * 2
for i = 0 to size - 1
temp(i) = in(i)
next
&in = null
alloc in, size * 2
for i = 0 to size - 1
in(i) = temp(i)
next
size = size * 2
return &in
endfunction
alloc x, size - 1
alloc y, size2 - 1
x(0) = 5
x(1) = 4
x(2) = 3
x(3) = 2
x(4) = 1
TextMode(TEXT_BUFFERED)
cls
printr "Testing array resizing"
for i = 0 to size - 1
printr x(i)
next
printr
&x = reSize(x, size)
&y = reSize(y, size2)
for i = 0 to size - 1
printr x(i)
next
printr "Done testing, press ENTER to continue"
printr
drawText()
while not ScanKeyDown(VK_RETURN)
wend
type Node
dim &nextNode as Node
dim &prevNode as Node
dim &object
dim isStart
dim isEnd
end type
type LinkedSequence
dim &Start as Node
dim &Back as Node
end type
dim &Test as LinkedSequence
alloc Test
function &NewNode(someStuff) as Node
dim &tempNode as Node
alloc tempNode
alloc tempNode.object
tempNode.object = someStuff
return &tempNode
endfunction
function InitLinkedSequence(&In as LinkedSequence)
dim x as integer = 0
&In.Start = NewNode(0)
&In.Back = NewNode(10)
In.Start.isStart = true
In.Back.isEnd = true
&In.Back.prevNode = &In.Start
&In.Start.nextNode = &In.Back
return 0
endfunction
function &AddLast(&In as LinkedSequence, stuff) as LinkedSequence
dim &tempList as LinkedSequence = &In
dim &tempNode as Node = &tempList.Start
while not tempNode.isEnd
&tempNode = &tempNode.nextNode
wend
&tempNode = &tempNode.prevNode
&tempNode.nextNode = NewNode(stuff)
&tempNode.nextNode.prevNode = &tempNode
&tempNode = &tempNode.nextNode
&tempNode.nextNode = &tempList.Back
&tempList.Back.prevNode = &tempNode
return &tempList
endfunction
InitLinkedSequence(Test)
dim &LoopNode as Node
&LoopNode = &Test.Start
printr "Initializing new linked sequence: "
while &LoopNode <> null
printr LoopNode.object
&LoopNode = &LoopNode.nextNode
wend
&Test = AddLast(Test, 1)
&Test = AddLast(Test, 2)
&Test = AddLast(Test, 3)
&Test = AddLast(Test, 4)
&Test = AddLast(Test, 5)
&Test = AddLast(Test, 6)
&Test = AddLast(Test, 7)
&Test = AddLast(Test, 8)
&Test = AddLast(Test, 9)
Test.Start.object = 0
Test.Back.object = 10
&LoopNode = &Test.Start
printr "Inserted 9 new nodes, did not explicitly make 9 new variables"
printr "Dynamic memory. Non-dynamic language. Hacks."
while &LoopNode <> null
printr LoopNode.object
&LoopNode = &LoopNode.nextNode
wend
printr "New results^^"
drawText()
I highly doubt this is a good way of going about making new memory on the fly, but hell, it's the only way I've ever seen it in this language.
Questions? Comments? Don't understand the significance? Drop a reply.
Happy coding ;D