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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public class CStack
{
private int [] M;
private int [] L;
private const int defaultCapacity = 10;
private int size;
public CStack()
{
this.size = 0;
this.M = new int [defaultCapacity];
this.L = new int[defaultCapacity];
}
public int Max()
{
int ma = this.M[0], id = 0;
for (int i = 1; i < defaultCapacity; ++i)
{
if (ma < this.M[i])
{
ma = this.M[i];
id = i;
}
}
return id;
}
public void Next()
{
int ma = 0, id = Max(), id2 = 0;
for (int i = 0; i < defaultCapacity; ++i)
{
for (int j = 0; j < defaultCapacity; ++j)
{
if (ma < this.M[j] && ma < this.M[id])
{
ma = this.M[j];
id2 = j;
}
}
this.L[id] = id2;
ma = 0;
id = id2;
}
}
public int Pop()
{
return this.M[--this.size];
}
public void Push(int newElement)
{
this.M[this.size++] = newElement;
}
}
static void Main(string[] args)
{
int []input = {9, 7, 11, 10, 5, 0};
CStack M = new CStack();
for (int i = 0; i < 6; ++i)
{
M.Push(input[i]);
}
M.Next();
}
}
}