public void AddAtStart(T value)
 {
     head = new SinglyLinkedNode <T> {
         Data = value, Next = head
     };
     size++;
 }
示例#2
0
        public T TakeAtStart()
        {
            var value = head.Data;

            head      = head.Next;
            tail.Next = head;
            size--;
            return(value);
        }
示例#3
0
        public T Pop()
        {
            var value = head.Data;

            head = head.Next;

            size--;
            return(value);
        }
示例#4
0
        public void Push(T item)
        {
            var newNode = new SinglyLinkedNode <T> {
                Data = item, Next = head
            };

            head = newNode;

            size++;
        }
        public T TakeAtStart()
        {
            if (size > 0)
            {
                var nextAfterHead = head.Next;
                var value         = head.Data;
                head = nextAfterHead;
                size--;

                return(value);
            }
            return(default(T));
        }
示例#6
0
        public T TakeAtEnd()
        {
            T   value       = tail.Data;
            var currentNode = head;

            do
            {
                currentNode = currentNode.Next;
            } while (currentNode.Next.Next != head);

            currentNode.Next = head;
            tail             = currentNode;
            size--;
            return(value);
        }
示例#7
0
        public void AddAtEnd(T item)
        {
            var newNode = new SinglyLinkedNode <T> {
                Data = item
            };

            if (size == 0)
            {
                head         = newNode;
                tail         = newNode;
                newNode.Next = head;
            }
            else
            {
                tail.Next    = newNode;
                tail         = newNode;
                newNode.Next = head;
            }
            size++;
        }
        public void AddAtEnd(T value)
        {
            var node = new SinglyLinkedNode <T> {
                Data = value, Next = null
            };

            if (head == null)
            {
                head = node;
            }
            else
            {
                var currentNode = head;

                while (currentNode.Next != null)
                {
                    currentNode = currentNode.Next;
                }
                currentNode.Next = node;
            }

            size++;
        }