예제 #1
0
 static void Main(string[] args)
 {
     var tune = new LinkedList<string>();
     tune.AddFirst("do"); // do
     tune.AddLast("so"); // do - so
     tune.AddAfter(tune.First, "re"); // do - re- so
     tune.AddAfter(tune.First.Next, "mi"); // do - re - mi- so
     tune.AddBefore(tune.Last, "fa"); // do - re - mi - fa- so
     tune.RemoveFirst(); // re - mi - fa - so
     tune.RemoveLast(); // re - mi - fa
     LinkedListNode<string> miNode = tune.Find("mi");
     tune.Remove(miNode); // re - fa
     tune.AddFirst(miNode); // mi - re - fa
     foreach (string s in tune)
     {
         Console.WriteLine(s);
     }
 }
예제 #2
0
    public static void Main(string[] args)
    {
      // Create a container and add three elements to it.
      LinkedList llc = new LinkedList();
      LLNode first = llc.AddObject("This is first string");
      LLNode second = llc.AddObject("This is second string");
      LLNode third = llc.AddObject("This is last string");

      // Add one at the beginning and one in the middle.
      LLNode newfirst = llc.AddObject(null, "Insert before the first string");
      LLNode newmiddle = llc.AddObject(second, "Insert between the second and third strings");

      // We can manipulate the iterator "manually"
      Console.WriteLine("Iterate through the container manually:");
      LinkedListIterator lli = (LinkedListIterator)llc.GetEnumerator();
      lli.Reset();
      while(lli.MoveNext())
      {
        string s = (string)lli.Current;
        Console.WriteLine(s);
      }

      // Or we can let foreach do it for us.
      Console.WriteLine("\nIterator using foreach:");
      foreach(string s in llc)
      {
        Console.WriteLine(s);
      }

      // Wait for user to acknowledge the results.
      Console.WriteLine("Press Enter to terminate...");
      Console.Read();
    }
예제 #3
0
 //LinkedListIterator - Constructor.
 public LinkedListIterator(LinkedList linkedList)
 {
   this._linkedList = linkedList;
   Reset();
 }