-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.cs
More file actions
38 lines (32 loc) · 767 Bytes
/
Stack.cs
File metadata and controls
38 lines (32 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FirstCsharp
{
public class Stack<T>
{
private const int Capacity = 100;
private T[] array = new T[Capacity];
private int Pointer;
public int Count { get { return Pointer; } }
public void Push(T value)
{
if (Pointer == Capacity)
throw new StackOverflowException("Stack overflowed");
array[Pointer++] = value;
}
public T Pop()
{
return array[--Pointer];
}
public T Peek()
{
return array[Pointer - 1];
}
public bool IsEmpty()
{
return Pointer == 0;
}
}
}