示例#1
0
        public T DeQueue()
        {
            var temp = Front;

            Front = Front.Next;
            if (this.Front == null)
            {
                this.Rear = null;
            }
            return(temp.Data);
        }
示例#2
0
        public string printList()
        {
            NodeSingly <T> n      = Head;
            string         result = "";

            while (n != null)
            {
                result += n.Data.ToString() + "->";
                n       = n.Next;
            }

            return(result);
        }
示例#3
0
        public void EnQueue(T data)
        {
            var newData = new NodeSingly <T>(data);

            if (Front == null && Rear == null)
            {
                Front = newData;
                Rear  = newData;
                return;
            }

            Rear.Next = newData;
            Rear      = newData;
        }
示例#4
0
        public void Append(NodeSingly <T> NodeSingly)
        {
            if (Head == null)
            {
                Head = NodeSingly;
                return;
            }

            var temp = Head;

            while (temp.Next != null)
            {
                temp = temp.Next;
            }
            temp.Next = NodeSingly;
        }
示例#5
0
        public void deleteNodeSingly(int position)
        {
            // If linked list is empty
            if (Head == null)
            {
                return;
            }

            // Store head NodeSingly
            NodeSingly <T> temp = Head;

            // If head needs to be removed
            if (position == 0)
            {
                // Change head
                Head = temp.Next;
                return;
            }

            // Find previous NodeSingly of the NodeSingly to be deleted
            for (int i = 0;
                 temp != null && i < position - 1;
                 i++)
            {
                temp = temp.Next;
            }

            // If position is more than number of NodeSinglys
            if (temp == null || temp.Next == null)
            {
                return;
            }

            // NodeSingly temp->next is the NodeSingly to be deleted
            // Store pointer to the next of NodeSingly to be deleted
            NodeSingly <T> next = temp.Next.Next;

            // Unlink the deleted NodeSingly from list
            temp.Next = next;
        }
示例#6
0
 public void Push(NodeSingly <T> NodeSingly)
 {
     NodeSingly.Next = this.Head;
     this.Head       = NodeSingly;
 }
示例#7
0
 public LinkedListSingly(NodeSingly <T> head)
 {
     Head = head;
 }
示例#8
0
 public NodeSingly(T data, NodeSingly <T> next = null)
 {
     Data = data;
     Next = next;
 }