예제 #1
0
        public void PrintValues()
        {
            SllNode runner = Head;

            while (runner != null)
            {
                Console.WriteLine(runner.Value);
                runner = runner.Next;
            }
        }
예제 #2
0
        public void PrintNextValue()
        {
            SllNode runner = Head;

            while (runner.Next != null)
            {
                Console.WriteLine("Current Node: " + runner.Value + "  .Next Value: " + runner.Next.Value);
                runner = runner.Next;
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            SinglyLinkedList newList = new SinglyLinkedList();

            newList.add(2).add(3).add(5).add(20);
            newList.printValues();
            newList.printValues();
            SllNode node = newList.find(5);

            Console.WriteLine(node.value);
        }
예제 #4
0
        static void Main(string[] args)
        {
            SllNode          one   = new SllNode(1);
            SllNode          two   = new SllNode(2);
            SllNode          three = new SllNode(3);
            SinglyLinkedList head  = new SinglyLinkedList();

            head.Head = one;
            one.Next  = two;
            two.Next  = three;
            Console.WriteLine(head.Find(3).Value);
        }
예제 #5
0
 public void Remove()
 {
     if (Head != null)
     {
         SllNode runner = Head;
         while (runner.Next.Next != null)
         {
             runner = runner.Next;
         }
         runner.Next = null;
     }
 }
예제 #6
0
            public int?Find(int value)
            {
                SllNode runner = Head;

                while (runner != null)
                {
                    if (runner.Value == value)
                    {
                        return(runner.Value);
                    }
                    runner = runner.Next;
                }
                return(null);
            }
예제 #7
0
 public void RemoveTail()
 {
     if (Head.Next == null)
     {
         Head = null;
     }
     else
     {
         SllNode runner = Head;
         while (runner.Next.Next != null)
         {
             runner = runner.Next;
         }
         runner.Next = null;
     }
 }
예제 #8
0
            public void PrintValues()
            {
                SllNode current = Head;

                if (current == null)
                {
                    Console.WriteLine("No nodes to print");
                }
                else
                {
                    while (current != null)
                    {
                        Console.WriteLine("Node: " + current.Value);
                        current = current.Next;
                    }
                }
            }
예제 #9
0
            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;
                }
            }
예제 #10
0
 public void printValues()
 {
     if (head == null)
     {
         Console.WriteLine("No values");
     }
     else
     {
         List <int> nodeValues = new List <int>();
         SllNode    runner     = head;
         while (runner != null)
         {
             nodeValues.Add(runner.value);
             runner = runner.next;
         }
         Console.WriteLine(string.Join(", ", nodeValues));
     }
 }
예제 #11
0
        public SllNode Find(int value)
        {
            SllNode runner = Head;

            while (runner != null)
            {
                if (runner.Value != value)
                {
                    runner = runner.Next;
                }
                else
                {
                    return(runner);
                }
            }
            Console.WriteLine("Not Found");
            return(null);
        }
예제 #12
0
 public SllNode find(int Ivalue)
 {
     if (head != null)
     {
         SllNode runner = head;
         while (runner != null)
         {
             if (runner.value == Ivalue)
             {
                 return(runner);
             }
             else
             {
                 runner = runner.next;
             }
         }
     }
     return(null);
 }
예제 #13
0
 public SinglyLinkedList remove()
 {
     if (head.next == null)
     {
         head = null;
         return(this);
     }
     if (head != null)
     {
         SllNode runner = head;
         while (runner.next.next != null)
         {
             runner = runner.next;
         }
         runner.next = null;
         return(this);
     }
     return(null);
 }
예제 #14
0
            public void Remove()
            {
                if (Head.Next == null)
                {
                    Head = null;
                }
                else
                {
                    SllNode runner    = Head;
                    SllNode runnerTwo = Head.Next;

                    while (runnerTwo.Next != null)
                    {
                        runner    = runnerTwo;
                        runnerTwo = runnerTwo.Next;
                    }

                    runner.Next = null;
                }
            }
예제 #15
0
 public void removeAt(int nthNode)
 {
     if (head != null)
     {
         int     count  = 0;
         SllNode runner = head;
         while (runner != null)
         {
             if (count == nthNode - 1)
             {
                 runner.next = runner.next.next;
             }
             else
             {
                 runner = runner.next;
                 count++;
             }
         }
     }
 }
예제 #16
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);
            }
        }
예제 #17
0
 public SinglyLinkedList()
 {
     head = null;
 }
예제 #18
0
 public SinglyLinkedList()
 {
     // your code here
     Head = null;
 }
예제 #19
0
 public SllNode(int value)
 {
     Value = value;
     Next  = null;
 }