Example #1
0
        public int Add(Transport d)
        {
            MyLinkedList nw = new MyLinkedList(d);

            if (first == null)
            {
                first = nw;
            }
            else
            {
                nw.next  = end;
                end.prev = nw;
            }
            end = nw;
            count++;
            return(count - 1);
        }
Example #2
0
 public MyLinkedList(MyLinkedList c)
 {
     while (c != null)
     {
         MyLinkedList list = c;
         list.next = c.next;
         list.prev = c.prev;
         c         = c.next;
         if (list.prev == null)
         {
             end = list;
         }
         if (list.next == null)
         {
             first = list;
         }
     }
 }
Example #3
0
        public void Remove(Transport value)
        {
            if (value == null)
            {
                throw new Exception();
            }
            if (count == 1 && data.Equals(value))
            {
                Clear();
                return;
            }
            MyLinkedList cur = end;

            if (cur.data.Equals(value))
            {
                end      = end.next;
                end.prev = null;
                count--;
                return;
            }
            while (cur.next != null)
            {
                if (cur != null)
                {
                    if (cur.data.Equals(value))
                    {
                        cur.next.prev = cur.prev;
                        cur.prev.next = cur.next;
                        count--;
                        return;
                    }
                }
                cur = cur.next;
            }
            if (cur.data.Equals(value))
            {
                cur.prev.next = null;
                count--;
            }
        }
Example #4
0
        public override bool Equals(object obj)
        {
            if (!(obj is MyLinkedList))
            {
                throw new TypeAccessException();
            }
            if (obj == null)
            {
                throw new ArgumentNullException();
            }

            MyLinkedList o   = obj as MyLinkedList;
            MyLinkedList cur = end;

            foreach (MyLinkedList it in cur)
            {
                if (!o.data.Equals(cur.data))
                {
                    return(false);
                }
                o = o.next;
            }
            return(true);
        }
Example #5
0
 public void Clear()
 {
     first = null;
     end   = null;
     count = 0;
 }