Singly LinkedList Traversal using C#


Declare a LinkedList using the LinkedList collection in X# −

var a = new LinkedList < string > ();

Now add elements to the LinkedList −

a.AddLast("Tim");
a.AddLast("Tom");

Let us see how to perform traversal in a LinkedList −

Example

using System;
using System.Collections.Generic;

public class Demo {
   public static void Main(string[] args) {
      var a = new LinkedList < string > ();
      a.AddLast("Tim");
      a.AddLast("Tom");

      foreach(var res in a) {
         Console.WriteLine(res);
      }
   }
}

Updated on: 22-Jun-2020

140 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements