Beispiel #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);
        }
Beispiel #2
0
 static public void PrintList(Node head)
 {
     if (head == null) return;
     Console.WriteLine(head.Value);
     PrintList(head.Next);
 }
Beispiel #3
0
 public Node(string s)
 {
     Value = s;
     Next = null;
 }
Beispiel #4
0
 public Node(string s, Node n)
 {
     Value = s;
     Next = n;
 }
Beispiel #5
0
 public Node()
 {
     Value = "";
     Next = null;
 }