Ejemplo n.º 1
0
 /// <summary>
 /// Same concept as above Find except that it finds the previous node to the one in Item
 /// </summary>
 /// <param name="Item">Genreic field used in the search</param>
 /// <returns>return node</returns>
 private DoubleNode <T> FindPrevious(T Item)
 {
     current = m_header;
     do
     {
         current = current.GetNext();
     }while (!(current.GetNext() == m_header) && (!current.GetNext().GetData().Equals(Item)));
     return(current);
 }
 /// <summary>
 /// This method is used to find the last value in the doubly linked list
 /// </summary>
 /// <returns>the found node</returns>
 private DoubleNode<T> FindLast()
 {
     current = m_header;
     while (!(current.GetNext() == null))
     {
         current = current.GetNext();
     }
     return current;
 }
 /// <summary>
 /// Print all data values in the linked list
 /// </summary>
 public void PrintList()
 {
     current = m_header;
     while (!(current.GetNext() == null))
     {
         Console.WriteLine(current.GetNext().GetData().ToString());
         current = current.GetNext();
     }
 }
 /// <summary>
 /// This method will remove the given Item from the list and ajust all links
 /// </summary>
 /// <param name="Item">Item to be removed</param>
 public void Remove(T Item)
 {
     DoubleNode<T> p = Find(Item);
     if (!(current.GetNext() == null))
     {
         p.GetPrev().SetNext(p.GetNext());
         p.GetNext().SetPrev(p.GetPrev());
         p.SetNext(null);
         p.SetPrev(null);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// This method will remove the given Item from the list and ajust all links
        /// </summary>
        /// <param name="Item">Item to be removed</param>
        public void Remove(T Item)
        {
            DoubleNode <T> p = FindPrevious(Item);

            if (!(p.GetNext() == m_header))
            {
                p.GetPrev().SetNext(p.GetNext());
                p.GetNext().SetPrev(p.GetPrev());
                p.SetNext(null);
                p.SetPrev(null);
            }
        }
        /// <summary>
        /// Method used to add node to end of the linked list
        /// </summary>
        /// <param name="newItem">The Item being added to the end of the linked list</param>
        public void AddToEnd(T newItem)
        {
            current = m_header;
            newNode = new DoubleNode<T>(newItem);

            while (!(current.GetNext() == null))
            {
                current = current.GetNext();
            }

            current.SetNext(newNode);
            newNode.SetPrev(current);
        }
 /// <summary>
 /// This private method is used to run a search through the linked list to find an object specified in Item
 /// </summary>
 /// <param name="Item">Generic object that is searched for in the Linked list</param>
 /// <returns>Generic node used in other methods</returns>
 private DoubleNode<T> Find(T Item)
 {
     current = m_header;
     while ((!(current.GetData().Equals(Item)) && (!(current.GetNext() == null))))
     {
         current = current.GetNext();
     }
     if (!current.GetData().Equals(Item))
     {
         current = null;
     }
     return current;
 }
        /// <summary>
        /// Insert used to add an Item anywhere into the list after any given value
        /// </summary>
        /// <param name="newItem">New Item being added into the linked list</param>
        /// <param name="after">After this value the new Item will be added</param>
        public void Insert(T newItem, T after)
        {
            newNode = new DoubleNode<T>(newItem);

            current = Find(after);
            newNode.SetNext(current.GetNext());
            newNode.SetPrev(current);
            current.SetNext(newNode);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Print all data values in the linked list
 /// </summary>
 public void PrintList()
 {
     current = m_header;
     do
     {
         Console.WriteLine(current.GetData());
         current = current.GetNext();
     }while (!(current == m_header));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// This method is used to find the last value in the doubly linked list
        /// </summary>
        /// <returns>the found node</returns>
        private DoubleNode <T> FindLast()
        {
            current = m_header;
            do
            {
                current = current.GetNext();
            }while (!(current.GetNext().Equals(m_header)));

            return(current);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// This method is used to check if the circularlist is empty of not
 /// </summary>
 /// <returns>Boolean value of true or false</returns>
 public bool IsEmpty()
 {
     return((m_header.GetNext() == null) && (m_header.GetPrev() == null));
 }