Im making a stack-like data structure, and i have a problem. I pass in an Integer with my Push function, but value:Object is null. Try running this.
Type stack
Field head:block
Method Push(value:Object)
b:block=New block
b.value=value
b.fore=head
head=b
EndMethod
Method Pop:Object()
If _head=Null Then Return Null
b:block=head
head=head.fore
value:Object=b.value
Release b
Return value
EndMethod
EndType
Type block
Field value:Object
Field fore:block
EndType
Function CreateStack:stack()
s:stack=New stack
s.head=Null
Return s
EndFunction
'*****'
stk:stack=CreateStack()
stk.push(3)
stk.push(2)
stk.push(1)
Print String(stk.pop())
Print String(stk.pop())
Print String(stk.pop())
Print String(stk.pop())
All I get are nulls, and I traced it back to my Push function. The parameter value:Object goes null when Ints are passed in. Is there anything I'm doing wrong? Plus, I looked at the code fore linked lists, and they do the same sort of thing, but they work fine.
|