namespace C_.Datastructures.Stack { public class Stack { internal StackNode? Head { get; set; } private int Count { get; set; } = 0; public static Stack Create() { //Create a new stack without a head return new Stack(); } public static Stack Create(T? value) { //Create a new Stack with a head return new Stack { Head = StackNode.Create(value, default), Count = 1 }; } public void Push(T? value) { //Add an Item to the top of the stack Count++; Head = StackNode.Create(value, Head); return; } public T? Pop() { //Take the item off of the top of the stack T? value = default; if (Count > 0) {//Assign the default value if there are any items left in the stack Count--; value = Head!.Value; Head = Head.Next; if (Count == 0) { Head = default; } } return value; } public T? Peek() { //View item on top of the stack if (Count > 0) { return Head!.Value; } return default; } public int GetCount() {//Return the number of items in the list return Count; } } }