Пример #1
0
        public void Remove(int value)
        {
            SllNode runner   = Head;
            SllNode previous = Head;

            while (runner != null)
            {
                if (runner.Value == value)
                {
                    if (runner == Head)
                    {
                        Head = runner.Next;
                        break;
                    }
                    else if (runner.Next == null)
                    {
                        previous.Next = null;
                        break;
                    }
                    else
                    {
                        previous.Next = runner.Next;
                        break;
                    }
                }
                else
                {
                    previous = runner;
                    runner   = runner.Next;
                }
            }
        }
Пример #2
0
 public void Remove(int n)
 {
     if (Head != null)
     {
         SllNode runner = Head;
         int     index  = 0;
         //if out of bounds
         if (n > this.Length())
         {
             Console.WriteLine("Out OF Bounds Sucka!");
             return;
         }
         else if (n == 0)
         {
             Head   = Head.Next;
             runner = null;
         }
         //Multi node list
         else
         {
             while (index + 1 != n)
             {
                 runner = runner.Next;
                 index++;
             }
             runner.Next = runner.Next.Next;
         }
     }
 }
Пример #3
0
        public void RemoveAt(int index)
        {
            SllNode runner = Head;

            for (int i = 0; i < index - 1; i++)
            {
                runner = runner.Next;
            }
            runner.Next = runner.Next.Next;
        }
Пример #4
0
        public void Remove()
        {
            SllNode runner = Head;

            while (runner.Next != null)
            {
                runner = runner.Next;
            }
            runner = null;
        }
Пример #5
0
        public SllNode Find(int value)
        {
            SllNode runner = Head;

            while (runner.Value != value && runner != null)
            {
                runner = runner.Next;
            }
            return(runner);
        }
Пример #6
0
        public void PrintValues()
        {
            SllNode runner = this.Head;

            while (runner != null)
            {
                Console.WriteLine(runner.Value);
                runner = runner.Next;
            }
        }
Пример #7
0
        public void Display()
        {
            SllNode runner = Head;

            Console.WriteLine(runner.Value);
            while (runner.Next != null)
            {
                runner = runner.Next;
                Console.WriteLine(runner.Value);
            }
        }
Пример #8
0
        public int Length()
        {
            int     length = 0;
            SllNode runner = Head;

            while (runner.Next != null)
            {
                runner = runner.Next;
                length++;
            }
            return(length);
        }
Пример #9
0
        public void Remove()
        {
            SllNode runner = this.Head;

            while (runner != null)
            {
                if (runner.Next.Next == null)
                {
                    runner.Next = null;
                }
                runner = runner.Next;
            }
        }
Пример #10
0
        public SllNode Find(int _int)
        {
            SllNode runner = this.Head;

            while (runner != null)
            {
                if (runner.Value == _int)
                {
                    return(runner);
                }
                runner = runner.Next;
            }
            return(null);
        }
Пример #11
0
        public SllNode Find(int i)
        {
            SllNode runner = Head;

            while (runner.Next != null)
            {
                if (runner.Value == i)
                {
                    return(runner);
                }
                runner = runner.Next;
            }
            Console.WriteLine("Not a True Value");
            return(null);
        }
Пример #12
0
 public void PrintValues()
 {
     if (Head == null)
     {
         Console.WriteLine("List is empty");
     }
     else
     {
         SllNode runner = Head;
         while (runner != null)
         {
             Console.WriteLine(runner.Value);
             runner = runner.Next;
         }
     }
 }
Пример #13
0
 public void Remove()
 {
     if (Head == null)
     {
         Console.WriteLine("List is empty");
     }
     else
     {
         SllNode runner = Head;
         while (runner.Next.Next != null)
         {
             runner = runner.Next;
         }
         runner.Next = null;
     }
 }
Пример #14
0
 public SinglyLinkedList Remove()
 {
     if (Head == null)
     {
         return(null);
     }
     else
     {
         SllNode runner = Head;
         while (runner.Next.Next != null)
         {
             runner = runner.Next;
         }
         runner.Next = null;
         return(this);
     }
 }
Пример #15
0
        public void PrintValues()
        {
            SllNode runner = Head;

            while (runner != null)
            {
                Console.WriteLine($"{runner.Value}");
                if (runner.Next != null)
                {
                    runner = runner.Next;
                }
                else
                {
                    break;
                }
            }
        }
        public void add(int value)
        {
            SllNode newNode = new SllNode(value);

            if (head == null)
            {
                head = newNode;
            }
            else
            {
                SllNode runner = head;
                while (runner.next != null)
                {
                    runner = runner.next;
                }
                runner.next = newNode;
            }
        }
Пример #17
0
        public void PrintVal()
        {
            SllNode runner = Head;

            if (runner != null)
            {
                while (runner.Next != null)
                {
                    Console.WriteLine(runner.Value);
                    runner = runner.Next;
                }
                Console.WriteLine(runner.Value);
            }
            else
            {
                Console.WriteLine("NOT A SllNODE");
            }
        }
Пример #18
0
        // SLL methods go here. As a starter, we will show you how to add a node to the list.
        public void Add(int value)
        {
            SllNode runner  = Head;
            SllNode newNode = new SllNode(value);

            if (Head == null)
            {
                Head = newNode;
            }
            else
            {
                while (runner.Next != null)
                {
                    runner = runner.Next;
                }
                runner.Next = newNode;
            }
        }
Пример #19
0
        // SLL methods go here. As a starter, we will show you how to add a node to the list.
        public SinglyLinkedList Add(int value)
        {
            SllNode newNode = new SllNode(value);

            if (Head == null)
            {
                Head = newNode;
                return(this);
            }
            else
            {
                SllNode runner = Head;
                while (runner.Next != null)
                {
                    runner = runner.Next;
                }
                runner.Next = newNode;
                return(this);
            }
        }
Пример #20
0
        public void Find(int num)
        {
            SllNode runner  = Head;
            int     counter = 0;

            while (runner.Value != num)
            {
                if (runner.Next == null)
                {
                    Console.WriteLine($"The number { num } does not exist in your list.");
                    return;
                }
                else
                {
                    runner   = runner.Next;
                    counter += 1;
                }
            }
            Console.WriteLine($"The number { num } was found at index { counter }!");
        }
Пример #21
0
 public void Remove()
 // public void Remove(int x)
 {
     if (Head != null)
     {
         SllNode runner = Head;
         //only one node at this point
         if (Head.Next == null)
         {
             Head = null;
         }
         //more than one node now (next = newNode)
         else
         {
             while (runner.Next.Next != null)
             {
                 runner = runner.Next;
             }
             runner.Next = null;
         }
     }
 }
Пример #22
0
        public void RemoveAt(int num)
        {
            int     counter = 0;
            SllNode runner  = Head;

            if (num == 0)
            {
                Head = runner.Next;
                return;
            }
            while (counter != num - 1)
            {
                if (runner.Next == null)
                {
                    Console.WriteLine("Index is out of list bounds.");
                    return;
                }
                counter++;
                runner = runner.Next;
            }
            runner.Next = runner.Next.Next;
        }
Пример #23
0
        public void Find(int value)
        {
            SllNode runner = Head;

            while (runner != null)
            {
                if (runner.Value == value)
                {
                    Console.WriteLine(runner.Value);
                    break;
                }
                else
                {
                    runner = runner.Next;
                    if (runner == null)
                    {
                        Console.WriteLine("Value doesn't exist");
                        break;
                    }
                }
            }
        }
Пример #24
0
        public void RemoveAt(int value)
        {
            SllNode runner = Head;
            int     index  = value++;

            while (index != 0)
            {
                index--;
                if (index == 0)
                {
                    Remove(runner.Value);
                }
                else
                {
                    runner = runner.Next;
                    if (runner == null)
                    {
                        Console.WriteLine("Not enough nodes");
                        break;
                    }
                }
            }
        }
Пример #25
0
 public SllNode(int value)
 {
     this.value = value;
     next       = null;
 }
Пример #26
0
 public SllNode(int value)
 {
     // your code here
     Value = value;
     Next  = null;
 }
Пример #27
0
 public SinglyLinkedList()
 {
     Head = null;
 }
 public SinglyLinkedLists()
 {
     head = null;
 }
Пример #29
0
 public SinglyLinkedList()
 {
     // your code here
     Head = null;
 }
Пример #30
0
 public SllNode(int value)
 {
     Value = value;
     Next  = null;
 }