예제 #1
0
        static void Main(string[] args)
        {
            Node head = null; //Empty List
            string data = null;

            //Populate my list
            do {
                Console.Write("Enter a string: ");
                data = Console.ReadLine();
                //Add data to list at end of list
                if (!string.IsNullOrEmpty(data))
                {
                    //Create my node
                    var temp = new Node(data); //Used for creating a new node
                    //Find last node
                    if (head == null)//List is empty
                    {
                        head = temp;
                    }
                    else
                    {
                        var current = head; //Reference to node that is currently of interest
                        while (current.Next != null) //If there is a next item
                            current = current.Next;//go to it.
                        //Now, insert after current (which should be the last item)
                        current.Next = temp;
                    }
                }
            }
            while (!string.IsNullOrEmpty(data));
            PrintList(head);
        }
예제 #2
0
 static public void PrintList(Node head)
 {
     if (head == null) return;
     Console.WriteLine(head.Value);
     PrintList(head.Next);
 }
예제 #3
0
 public Node(string s)
 {
     Value = s;
     Next = null;
 }
예제 #4
0
 public Node(string s, Node n)
 {
     Value = s;
     Next = n;
 }
예제 #5
0
 public Node()
 {
     Value = "";
     Next = null;
 }