示例#1
0
        public void InsertAtHead(object val)
        {
            listNode newNode = new listNode(val);

            newNode.Next = this.head;
            this.head    = newNode;
        }
示例#2
0
        public void Push(Object k)
        {
            listNode newNode = new listNode(k);

            newNode.Next = _top;
            _top         = newNode;
            _size++;
        }
示例#3
0
        public void print()
        {
            listNode current = this.head;

            while (current != null)
            {
                Console.WriteLine(current.Data);
                current = current.Next;
            }
        }
示例#4
0
        public listNode remove()
        {
            if (_head == null)
            {
                _tail = null;

                throw new Exception("the list is already empty");
            }
            listNode current = _head;

            _head = _head.Next;
            size--;
            updateMin();
            return(current);
        }
示例#5
0
        public listNode Pop(Object k)
        {
            listNode result;

            if (_top == null)
            {
                throw new Exception("Stack is empty");
            }

            result = _top;
            _top   = _top.Next;
            _size--;

            return(result);
        }
示例#6
0
        private void updateMin()
        {
            if (_head == null)
            {
                return;
            }
            listNode current = _head;

            while (current.Next != null)
            {
                if ((int)minElement < (int)current.Data)
                {
                    minElement = current.Data;
                }
                current = current.Next;
            }
        }
示例#7
0
        public void deleteNode(object val)
        {
            listNode current = this.head;

            if (head != null)
            {
                while (current.Next != null)
                {
                    if (current.Next.Data == val)
                    {
                        current.Next = current.Next.Next;
                        return;
                    }
                    current = current.Next;
                }
            }
        }
示例#8
0
        public void insertAtEnd(object val)
        {
            bool flag = false;

            if (head == null)
            {
                InsertAtHead(val);
            }
            else
            {
                listNode current = this.head;
                while (current.Next != null)
                {
                    current = current.Next;
                }

                listNode newNode = new listNode(val);
                current.Next = newNode;
                size++;
            }
        }
示例#9
0
        public void queueAdd(object k)
        {
            listNode current;

            if (_tail == null)
            {
                current    = new listNode(k);
                _head      = _tail = current;
                minElement = k;

                size++;
            }
            else
            {
                listNode newNode = new listNode(k);
                _tail.Next = newNode;
                _tail      = newNode;
                if ((int)k < (int)minElement)
                {
                    minElement = k;
                }
                size++;
            }
        }
示例#10
0
 public Queues()
 {
     _head = null;
     _tail = null;
     size  = 0;
 }
示例#11
0
 public LinkedList_imp()
 {
     head = null;
     size = 0;
 }
示例#12
0
 public Stacks()
 {
     _top  = null;
     _size = 0;
 }