예제 #1
0
        public T Pop()
        {
            MyStackElement <T> toReturn = content[position - 1];

            position--;
            return(toReturn.value);
        }
예제 #2
0
        public MyStackElement <T>[] CopyArray(MyStackElement <T>[] arr)
        {
            size = size * 2;
            MyStackElement <T>[] toReturn = new MyStackElement <T> [size];

            for (int i = 0; i < arr.Length; i++)
            {
                toReturn[i] = arr[i];
            }

            return(toReturn);
        }
예제 #3
0
        public void Push(T value)
        {
            MyStackElement <T> elementToAdd = new MyStackElement <T>()
            {
                value = value
            };

            if (position == content.Length - 1)
            {
                content = CopyArray(content);
            }

            if (content[0] == null)
            {
                content[0]          = elementToAdd;
                content[0].position = 0;
                position++;
            }
            else
            {
                content[position] = elementToAdd;
                position++;
            }
        }