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){
|
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)
|
if (Count > 0)
|
||||||
{
|
{
|
||||||
Count++;
|
|
||||||
Head = StackNode<T>.Create(value, Head);
|
Head = StackNode<T>.Create(value, Head);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Head = StackNode<T>.Create(value, default);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Pop(){
|
public T? Pop(){
|
||||||
@ -38,6 +40,10 @@ namespace C_.Datastructures
|
|||||||
Count--;
|
Count--;
|
||||||
value = Head!.Value;
|
value = Head!.Value;
|
||||||
Head = Head.Next;
|
Head = Head.Next;
|
||||||
|
if (Count == 0)
|
||||||
|
{
|
||||||
|
Head = default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user