Tag Archives: stack

Do Value Types in C# always go on the stack?

It is quite well-known that value-types are created on the Stack (sometimes in registers as well depending on the allocation strategy) and reference types are based in the Heap area of memory. But when you are creating a custom type and you wish to embed value types in there, where would they reside? So it […]

0  

Implementing a Stack in python

To implement a Stack in python, we simply need to extend the existing list class! class Stack(list): def push(self, data): self.append(data) def tos(self): if self: return self[-1] def peek(self, index): if self and 0 <= index < len(self): return self[index] def __iter__(self): if self: ptr = len(self) – 1 while ptr >= 0: yield self[ptr] […]

0