-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.cs
43 lines (38 loc) · 1001 Bytes
/
Stack.cs
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
39
40
41
42
43
using System;
using System.Collections;
namespace CSharpIntermediate
{
partial class Program
{
public class Stack
{
private ArrayList List { get; set; }
public Stack()
{
List = new ArrayList();
}
public void Push(object obj)
{
if (obj == null)
{
throw new InvalidOperationException("Value can't be null.");
}
List.Add(obj);
}
public object Pop()
{
if (List.Count == 0)
{
throw new InvalidOperationException("Can't execute Pop with empty list.");
}
var obj = List[List.Count - 1];
List.RemoveAt(List.Count - 1);
return obj;
}
public void Clear()
{
List.Clear();
}
}
}
}