ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 제네릭
    프로그래밍 언어/클래스 2011. 7. 28. 17:04
    using System;

    class Stack<StackType>
    {
        private StackType[] stack = new StackType[100];

        private int sp = -1;

        public void Push(StackType element)
        {
            stack[++sp] = element;
        }

        public StackType Pop()
        {
            return stack[sp--];
        }
    }

    class GenericClassApp
    {
        public static void Main()
        {
            Stack<int> stk1 = new Stack<int>();        // 정수형 스택
            Stack<double> stk2 = new Stack<double>();  // 실수형 스택

            ..
        }
    }

Designed by Tistory.