using System using System Collections Generic using System Linq using

 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
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public class Stack<T>
{
private T [] M;
private const int a = 25;
private int size;
public CStack()
{
this.size = 0;
this.M = new T [a];
}
public T Pop()
{
--this.size
return this.M[this.size];
}
public void Push(T first)
{
this.size++
this.M[this.size] = first;
}
}
static void Main(string[] args)
{
int []digital = {-1, 3, 4, 0, -2, 3, -1, -6, 3, 8,5,6,1,4,6,5,2,4,6,-6,-7,0,0,3,7};
CStack<int> pos = new CStack<int>();
int count = 0;
for (int i = 0; i < 25; ++i)
{
if (digital[i] < 0)
{
System.Console.WriteLine(digital[i]);
}
else
{
pos.Push(digital[i]);
count++;
}
}
for (int i = 0; i < count; ++i)
{
System.Console.WriteLine(pos.Pop());
}
System.Console.ReadKey();
}
}
}