class · System
Stack<T>
public class Stack<T>
Last in, first out: Push and Pop at the top.
- Kind
- class
- Namespace
- System
- Assembly
- System.Core
- Access
- public
- Source file
List.ant
Type parameters
| Name | Constraints |
|---|---|
T | any type |
Inheritance
- Base classes
-
AnyStack<T>
Constructors
new()
#
Properties
Methods
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
Stack<T> as Antril, decompiled from its Larva HIR.
// System.Stack — System.Core (decompiled from Larva HIR)
into namespace System
{
/// Last in, first out: Push and Pop at the top.
public class Stack<T>
{
T[] items;
i32 count;
[NoInline]
Grow()
{
T[] bigger = new T[items.Length * 2];
loop (i32 i = 0..count)
bigger[i] = items[i];
items = bigger;
}
public:
new()
{
items = new T[8];
}
Push(T item)
{
if (count == items.Length)
Grow();
items[count] = item;
count++;
}
Pop() : T
{
if (count == 0)
throw new InvalidOperationError("Pop on an empty stack");
count--;
T top = items[count];
items[count] = default(T);
return top;
}
Peek() : T
{
if (count == 0)
throw new InvalidOperationError("Peek on an empty stack");
return items[count - 1];
}
Clear()
{
loop (i32 i = 0..count)
items[i] = default(T);
count = 0;
}
i32 Count
{
get => count;
}
bool IsEmpty
{
get => count == 0;
}
}
}