Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Vezba_04_2017
- {
- class GenericStack<T>
- {
- private T[] a;
- private int count;
- public GenericStack()
- {
- a = new T[10];
- count = 0;
- }
- public bool IsEmpty
- {
- get { return count == 0; }
- }
- public void Push(T x)
- {
- if (count > a.Length)
- throw new InvalidOperationException("Ju kenot du dat, d stek iz ful");
- a[count] = x;
- count++;
- }
- public T Pop ()
- {
- if (IsEmpty)
- throw new InvalidOperationException("Stek iz empti");
- count--;
- return a[count];
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- for (int i = count - 1; i >= 0; i--)
- {
- sb.AppendFormat("{0} ", a[i]);
- }
- return sb.ToString();
- }
- }
- }
Add Comment
Please, Sign In to add comment