Stack Completed

This commit is contained in:
Luke Else 2022-03-31 21:32:42 +01:00
parent 40f73375b9
commit bff4abff01

View File

@ -21,7 +21,7 @@ namespace C_.Datastructures
} }
public void Push(T value){ public void Push(T value){
//Add an Item to the end of the list //Add an Item to the top of the stacks
if (Count > 0) if (Count > 0)
{ {
Count++; Count++;
@ -31,6 +31,7 @@ namespace C_.Datastructures
} }
public T? Pop(){ public T? Pop(){
//Take the item off of the top of the stack
T? value = default; T? value = default;
if (Count > 0) if (Count > 0)
{//Assign the default value if there are any items left in the stack {//Assign the default value if there are any items left in the stack
@ -42,6 +43,7 @@ namespace C_.Datastructures
} }
public T? Peek(){ public T? Peek(){
//View item on top of the stack
if (Count > 0) if (Count > 0)
{ {
return Head!.Value; return Head!.Value;