示例#1
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            LinkedNode <T> temp = Head;

            while (temp != null)
            {
                array[arrayIndex++] = Head.Data;
                temp = temp.Next;
            }
        }
示例#2
0
        public void print( )
        {
            LinkedNode <T> temp = Head;

            while (temp != null)
            {
                Console.WriteLine(temp.Data);
                temp = temp.Next;
            }
        }
示例#3
0
 public void removeFirst( )
 {
     if (Head != null)
     {
         Head = Head.Next;
         if (Head == null)
         {
             Tail = null;
         }
     }
 }
示例#4
0
        public void addFirst(LinkedNode <T> node)
        {
            LinkedNode <T> temp = Head;

            Head      = node;
            Head.Next = temp;
            if (temp == null)
            {
                Tail = Head;
            }
        }
示例#5
0
        public IEnumerator <T> GetEnumerator( )
        {
            LinkedNode <T> current = Head;

            while (current != null)
            {
                yield return(current.Data);

                current = current.Next;
            }
        }
示例#6
0
 public void addLast(LinkedNode <T> node)
 {
     if (Head == null)
     {
         Head = node;
     }
     else
     {
         Tail.Next = node;
     }
     Tail = node;
 }
示例#7
0
        public bool Contains(T item)
        {
            LinkedNode <T> temp = Head;

            while (temp != null && !temp.Data.Equals(item))
            {
                temp = temp.Next;
            }
            if (temp != null)
            {
                return(true);
            }
            return(false);
        }
示例#8
0
 public void removeLast( )
 {
     if (Tail != null)
     {
         if (Head.Next == null)
         {
             Tail = null;
             Head = null;
         }
         else
         {
             LinkedNode <T> temp = Head;
             while (temp.Next != Tail)
             {
                 temp = temp.Next;
             }
             temp.Next = null;
             Tail      = temp;
         }
     }
 }
示例#9
0
 public LinkedList( )
 {
     Head = null;
     Tail = null;
 }