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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public class CStack<T>
{
private T [] M;
private const int defaultCapacity = 10;
private int size;
public CStack()
{
this.size = 0;
this.M = new T [defaultCapacity];
}
public T Pop()
{
return this.M[--this.size];
}
public void Push(T newElement)
{
this.M[this.size++] = newElement;
}
}
static void Main(string[] args)
{
int []input = {-1, 3, 4, 0, -2, 3, -1, -6, 3, 8};
CStack<int> pos = new CStack<int>();
int count = 0;
for (int i = 0; i < 10; ++i)
{
if (input[i] < 0)
{
System.Console.WriteLine(input[i]);
}
else
{
pos.Push(input[i]);
count++;
}
}
for (int i = 0; i < count; ++i)
{
System.Console.WriteLine(pos.Pop());
}
System.Console.ReadKey();
}
}
}