Mega Code Archive

 
Categories / C# / Collections Data Structure
 

Change the last node be yesterday

using System; using System.Text; using System.Collections.Generic; public class Example {     public static void Main()     {         // Create the link list.         string[] words ={ "the", "fox", "jumped", "over", "the", "dog" };         LinkedList<string> sentence = new LinkedList<string>(words);         Display(sentence, "The linked list values:");                  sentence.RemoveLast();         sentence.AddLast("yesterday");         Display(sentence, "Test 3: Change the last node to 'yesterday':");     }     private static void Display(LinkedList<string> words, string test)     {         Console.WriteLine(test);         foreach (string word in words)         {             Console.Write(word + " ");         }     } }