Add new node before the specified existing node in LinkedList in CSharp
Description
The following code shows how to add new node before the specified existing node in LinkedList.
Example
/*w ww . j a va2s .c o m*/
using System;
using System.Collections;
using System.Collections.Generic;
public class GenericCollection
{
public static void Main()
{
LinkedList<String> ll = new LinkedList<String>();
ll.AddLast( "A" );
ll.AddLast( "B" );
ll.AddLast( "C" );
ll.AddLast( "java2s.com" );
foreach(string s in ll){
Console.WriteLine(s);
}
ll.AddBefore(ll.First,ll.Last );
foreach(string s in ll){
Console.WriteLine(s);
}
}
}
The code above generates the following result.