コード例 #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;
 }