69
1
using System;
2
3
public class Stack<T> {
4
readonly int max_size;
5
int index = 0;
6
public int size { get; set; }
7
T[] items = null;
8
9
public Stack() : this(100) { } // default max_size of 100
10
11
public Stack(int size) {
12
max_size = size;
13
items = new T[max_size];
14
}
15
16
// Push - Adds item to the top of the stack
17
public void Push(T item) {
18
if (size >= max_size)
19
throw new StackOverflowException();
20
21
items[index++] = item; // adds item in next spot
22
size++; // increments actual size
23
}
24
Cached Result
Hello I am a genie, you have three wishes
what would you like to wish for?
>
what would you like to wish for?