Example #1
0
 //Update
 public void Add(int val)
 {
     if (head == null)
     {
         head = new DLNode(val);
         tail = new DLNode(val);
     }
     else
     {
         DLNode curr = tail;
         curr.next = new DLNode(val);
         tail      = curr.next;
     }
     Count++;
 }
Example #2
0
        //Read pt 1
        public Boolean Contains(int val)
        {
            DLNode curr = head;

            while (curr != null)
            {
                if (curr.val == val)
                {
                    return(true);
                }
                else
                {
                    curr = curr.next;
                }
            }
            return(false);
        }
Example #3
0
        public int Captcha1()
        {
            int    result = 0;
            int    lCount = 0;
            DLNode curr   = head;

            while (lCount < Count)
            {
                if (curr.val == curr.last.val)
                {
                    result += curr.val;
                }
                lCount++;
                curr = curr.next;
            }
            return(result);
        }
Example #4
0
 public void Add(int val)
 {
     if (head == null)
     {
         head      = new DLNode(val);
         head.next = head;
         head.last = head;
         tail      = head;
     }
     else
     {
         tail.next      = new DLNode(val);
         tail.next.next = head;
         tail.next.last = tail;
         tail           = tail.next;
     }
 }
Example #5
0
 public CLL AddChar(string val)
 {
     if (head == null)
     {
         head      = new DLNode(Convert.ToInt32(val));
         head.next = head;
         head.last = head;
         tail      = head;
     }
     else
     {
         tail.next      = new DLNode(Convert.ToInt32(val));
         tail.next.next = head;
         tail.next.last = tail;
         tail           = tail.next;
     }
     return(this);
 }
Example #6
0
 public CLL StringToCLL(string val)
 {
     foreach (char item in val)
     {
         if (head == null)
         {
             head      = new DLNode(Convert.ToInt32(item));
             head.next = head;
             head.last = head;
             tail      = head;
         }
         else
         {
             tail.next      = new DLNode(Convert.ToInt32(item));
             tail.next.next = head;
             tail.next.last = tail;
             tail           = tail.next;
         }
     }
     return(this);
 }
Example #7
0
        //Delete
        public DLNode Remove(int val)
        {
            DLNode result = null;

            if (!Contains(val))
            {
                return(null);
            }
            else if (head.val == val && head == tail)
            {
                result = head;
                head   = null;
                tail   = null;
            }
            else if (head.val == val)
            {
                result = head;
                head   = head.next;
            }
            else
            {
                DLNode curr = head;
                while (curr.next != null)
                {
                    if (curr.next.val == val)
                    {
                        result = curr.next;
                        if (tail == curr.next)
                        {
                            tail = curr;
                        }
                        curr.next = curr.next.next;
                    }
                    curr = curr.next;
                }
            }
            Count--;
            return(result);
        }
Example #8
0
 public DLNode(int val)
 {
     this.val = val;
     next     = null;
     last     = null;
 }
Example #9
0
 //Create
 public DLL()
 {
     head  = null;
     tail  = null;
     Count = 0;
 }