Ale klasa to już programowanie obiektowe, a ma być stos napisany strukturalnie.
Jak rozumiem dla ciebie kod poniżej to programowanie obiektowe?
using System;
using System.Linq;
using System.Collections.Generic;
public class Test
{
public class IntStack {
public IList<int> Data { get; set; }
public static void Init(IntStack stack) {
stack.Data = new List<int>();
}
public static void Push(IntStack stack, int value) {
stack.Data.Add(value);
}
public static int Pop(IntStack stack) {
var value = stack.Data[stack.Data.Count - 1];
stack.Data.RemoveAt(stack.Data.Count - 1);
return value;
}
public static void Print(IntStack stack) {
Console.WriteLine(string.Join(", ", stack.Data.Select(i => i.ToString())));
}
}
public static void Main()
{
var stack = new IntStack();
IntStack.Init(stack);
IntStack.Push(stack, 3);
IntStack.Push(stack, 4);
IntStack.Push(stack, 5);
IntStack.Print(stack);
Console.WriteLine("last: {0}", IntStack.Pop(stack));
IntStack.Pop(stack);
IntStack.Print(stack);
}
}