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

            position--;
            return(toReturn.value);
        }
Beispiel #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);
        }
Beispiel #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++;
            }
        }