using System;

namespace MyCompiler {
    class Node {
        public int data;
        public Node next = null;
        
        public Node(int value) { data = value; }

        public override string ToString() {
            string output = (next != null) ? $"{next}, " : "";            
            return $"{output}{data}";
        }
    }
    class Stack {
        private Node top = null;

        public Stack() { Console.WriteLine($"{this}"); }

        public void Push(int value) {
            var node = new Node(value);
            node.next = top;
            top = node;
            Console.WriteLine($"push {value}");
            Console.WriteLine($"{this}");
        }

        public int? Pop() {
            if (top == null) {
                return null;
            }
            int data = top.data;
            top = top.next;
            Console.WriteLine($"pop {data}");
            Console.WriteLine($"{this}");
            return data;
        }

        public override string ToString() {
            return $"Stack: [{top}]";
        }
    }
    class Program {
        public static void Main(string[] args) {
            
            var stack = new Stack();      
            
            for (var i = 1; i < 4; i++) {
                stack.Push(i);
            } 
            
            for (var i = 1; i < 10; i++) {
                stack.Pop();
            } 
        }
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: