Fixed Push and Pop methods on Stack
This commit is contained in:
parent
1738ef0e5a
commit
c54401fdbb
@ -21,13 +21,15 @@ namespace C_.Datastructures
|
||||
}
|
||||
|
||||
public void Push(T value){
|
||||
//Add an Item to the top of the stacks
|
||||
//Add an Item to the top of the stack
|
||||
Count++;
|
||||
if (Count > 0)
|
||||
{
|
||||
Count++;
|
||||
Head = StackNode<T>.Create(value, Head);
|
||||
return;
|
||||
}
|
||||
Head = StackNode<T>.Create(value, default);
|
||||
return;
|
||||
}
|
||||
|
||||
public T? Pop(){
|
||||
@ -38,6 +40,10 @@ namespace C_.Datastructures
|
||||
Count--;
|
||||
value = Head!.Value;
|
||||
Head = Head.Next;
|
||||
if (Count == 0)
|
||||
{
|
||||
Head = default;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user