-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nov23HanoyTowerClassPart1.cs
45 lines (45 loc) · 1.07 KB
/
Nov23HanoyTowerClassPart1.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
44
45
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HanoyTower
{
public class Tower
{
private List<int> list = new List<int>();
public int Count => list.Count;
public int this [int i]
{
get
{
if (i >= 0 && i < Count)
return list[i];
throw new Exception("Asi Bror");
}
set
{
if (i >= 0 && i < Count) list[i] = value;
else throw new IndexOutOfRangeException();
}
}
public void Add(int a)
{
if (list.Count != 0)
{
if (a < list[list.Count - 1])
{
list.Add(a);
}
else throw new Exception(""+a);
}
else list.Add(a);
}
public void Remove()
{
if (list.Count == 0)
return;
list.RemoveAt(Count - 1);
}
}
}