Doubly-linked list/Definition: Difference between revisions

Add C sharp solution
(Add C sharp solution)
Line 340:
}
}</lang>
 
=={{header|C sharp}}==
<lang C sharp>
using System.Collections.Generic;
namespace Doubly_Linked_List
{
class Program
{
static void Main(string[] args)
{
LinkedList<string> list = new LinkedList<string>();
list.AddFirst(".AddFirst() adds at the head.");
list.AddLast(".AddLast() adds at the tail.");
LinkedListNode<string> first = list.Find(".AddFirst() adds at the head.");
list.AddAfter(first, ".AddAfter() adds after a specified node.");
LinkedListNode<string> last = list.Find(".AddLast() adds at the tail.");
list.AddBefore(last, "Betcha can't guess what .AddBefore() does.");
 
System.Console.WriteLine("Forward:");
foreach (string nodeValue in list) { System.Console.WriteLine(nodeValue); }
 
System.Console.WriteLine("\nBackward:");
LinkedListNode<string> current = last;
while (current != null)
{
System.Console.WriteLine(current.Value);
current = current.Previous;
}
}
}
}
 
/* Output:
Forward:
.AddFirst() adds at the head.
.AddAfter() adds after a specified node.
Betcha can't guess what .AddBefore() does.
.AddLast() adds at the tail.
 
Backward:
.AddLast() adds at the tail.
Betcha can't guess what .AddBefore() does.
.AddAfter() adds after a specified node.
.AddFirst() adds at the head.
*/
</lang>
 
=={{header|Common Lisp}}==
Anonymous user