示例#1
0
 //Update
 public void Add(int val)
 {
     if (head == null)
     {
         head = new SLNode(val);
     }
     else
     {
         SLNode curr = head;
         while (curr.next != null)
         {
             curr = curr.next;
         }
         curr.next = new SLNode(val);
     }
     Count++;
 }
示例#2
0
        //Read part 1
        public Boolean Contains(int val)
        {
            SLNode curr = head;

            while (curr != null)
            {
                if (curr.val == val)
                {
                    return(true);
                }
                else
                {
                    curr = curr.next;
                }
            }
            return(false);
        }
示例#3
0
 //Delete
 public SLNode Remove(int val)
 {
     if (!Contains(val))
     {
         Console.WriteLine("Value Not Found!");
     }
     else
     {
         if (head.val == val)
         {
             SLNode temp = head;
             head = head.next;
             Count--;
             return(temp);
         }
         else
         {
             SLNode curr = head;
             while (curr.next != null)
             {
                 if (curr.next.val == val)
                 {
                     SLNode temp = curr.next;
                     curr.next = curr.next.next;
                     Count--;
                     return(temp);
                 }
                 else
                 {
                     curr = curr.next;
                 }
             }
         }
     }
     return(null);
 }
示例#4
0
 //Create
 public SLL()
 {
     head  = null;
     Count = 0;
 }
示例#5
0
 public SLNode(int val)
 {
     this.val  = val;
     this.next = null;
 }