示例#1
0
        private void PrintStackToGridView(DataGridView grid)
        {
            grid.Rows.Clear();

            StackElement currentElement = top;

            while (currentElement != null)
            {
                grid.Rows.Add(currentElement.value.ToString());
                currentElement = currentElement.prev;
            }
        }
示例#2
0
        public int FindLowestPage(Dictionary <int, int> items)
        {
            StackElement currentElement = top;
            int          lowestPage     = -1;

            while (currentElement != null)
            {
                if (items.Values.Contains(currentElement.value))
                {
                    lowestPage = currentElement.value;
                }
                currentElement = currentElement.prev;
            }
            return(lowestPage);
        }
示例#3
0
        public void Push(int value, DataGridView grid)
        {
            StackElement newElement = new StackElement(value);

            if (bottom == null)
            {
                bottom = top = newElement;
            }
            else
            {
                StackElement currentElement = bottom;
                while (true)
                {
                    if (currentElement.value == value)
                    {
                        if (currentElement == bottom && currentElement == top)
                        {
                            PrintValues();
                            return;
                        }
                        else if (currentElement == bottom)
                        {
                            bottom              = bottom.next;
                            bottom.prev         = null;
                            top.next            = currentElement;
                            currentElement.prev = top;
                            top = currentElement;
                            currentElement.next = null;
                            PrintValues();
                            return;
                        }
                        else if (currentElement == top)
                        {
                            PrintValues();
                            return;
                        }
                        else
                        {
                            currentElement.prev.next = currentElement.next;
                            currentElement.next.prev = currentElement.prev;
                            top.next            = currentElement;
                            currentElement.prev = top;
                            top = currentElement;
                            currentElement.next = null;
                            PrintValues();
                            return;
                        }
                    }
                    if (currentElement.next == null)
                    {
                        break;
                    }
                    else
                    {
                        currentElement = currentElement.next;
                    }
                }
                top.next        = newElement;
                newElement.prev = top;
                top             = newElement;
                newElement.next = null;
                PrintValues();
                PrintStackToGridView(grid);
            }
        }