Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace ConsoleApp6
- {
- class Stack
- {
- int[] Buf;
- int n;
- int top;
- bool empty, full;
- public int nSt { get { return n; } }
- public bool Empty { get { return empty; } private set { empty = value; } }
- public bool Full { get { return full; } private set { full = value; } }
- public Stack(int n)
- {
- if (n == 0) throw new Exception("01");
- this.n = n;
- Buf = new int[n];
- top = 0;
- Empty = true;
- Full = false;
- }
- public void push(int t)
- {
- if (Full) throw new Exception("21");
- Buf[top++] = t;
- if (top >= n) Full = true;
- Empty = false;
- }
- public int pop()
- {
- if (Empty) throw new Exception("11");
- if (top == 0) Empty = true;
- return Buf[--top];
- }
- class Program
- {
- static void Main()
- {
- int i;
- Stack oSt;
- int r;
- StreamReader R = new StreamReader("in.txt");
- StreamWriter W = new StreamWriter("out.txt");
- int[] A;
- string[] As;
- int n;
- As = R.ReadLine().Split(',');
- n = As.Length;
- A = new int[n];
- for (i = 0; i < n; i++) A[i] = Convert.ToInt32(As[i]);
- for (i = 0; i <= 4; i++)
- {
- try
- {
- switch (i)
- {
- case 0: oSt = new Stack(i); break;
- case 1: oSt = new Stack(1); r = oSt.pop(); break;
- case 2:
- oSt = new Stack(1);
- oSt.push(i); oSt.push(i + 1); break;
- case 3:
- oSt = new Stack(3);
- {
- for (int j = 0; j < oSt.nSt; j++)
- {
- oSt.push(j + 1);
- }
- W.WriteLine("Stack 3: O'key");
- for (int j = 0; j < oSt.nSt; j++)
- {
- W.Write(" " + oSt.pop());
- }
- W.WriteLine();
- }
- break;
- case 4:
- oSt = new Stack(n);
- {
- for (int j = 0; j < oSt.nSt; j++)
- oSt.push(A[j]);
- W.WriteLine("Stack 4: O'key");
- while (!oSt.Empty)
- W.Write(" " + oSt.pop());
- W.WriteLine();
- }
- break;
- }
- }
- catch (Exception ob)
- {
- switch (ob.Message[0])
- {
- case '0':
- W.WriteLine("size=0"); break;
- case '1':
- W.WriteLine("read error"); break;
- case '2':
- W.WriteLine("write error"); break;
- }
- }
- }
- R.Close();
- W.Close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement