Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SimpleAdjListExample { class Program { static void Main(string[] args) { Node<string> first = new Node<string>(); Node<string> second = new Node<string>(); Node<string> third = new Node<string>(); first.item = "to"; second.item = "be"; third.item = "or"; first.next = second; second.next = third; // insert to begin of list Node<string> oldfirst = first; first = new Node<string>(); first.item = "not"; first.next = oldfirst; //delete from begin first = null; //insert to the end Node<string> oldlast = third; third = new Node<string>(); third.item = "some item"; // traverse for (Node<string> x = first; x != null; x = x.next) { x.item = "someValue"; } } } public class Node<T> { public T item; public Node<T> next; } } |