示例#1
0
 public void AddToEnd(int data)
 {
     if (nextNode == null)
     {
         nextNode = new Node(data);
     }
     else
     {
         nextNode.AddToEnd(data);
     }
 }
示例#2
0
        static void Main(string[] args)
        {
            //creates a new Node with a head value of 7
            Node myNode = new Node(7);

            // adds a new node in myNode by updating Nodes pointer value and creating a new node with the new data and new pointer

            // this is not scalable
            myNode.next = new Node(5);
            //better way is to use the new method AddToEnd
            myNode.AddToEnd(12);
            myNode.AddToEnd(15);
            // call print method
            myNode.Print();
        }
示例#3
0
 public void AddToEnd(int data)
 {
     if (headNode == null)
     {
         headNode = new Node(data);
     }
     else
     {
         headNode.AddToEnd(data);
     }
 }
示例#4
0
 public void AddToEnd(int data)
 {
     if (next == null) //end of the list
     {
         next = new Node(data);
     }
     else
     {
         next.AddToEnd(data);
     }
 }
 public void AddToEnd(string data)
 {
     if (next == null)
     {
         next = new Node(data);
     }
     else
     {
         next.AddToEnd(data);
     }
 }