c# - Creating a very simple linked list -
i trying create linked list see if can, , having trouble getting head around it. have example of simple implementation of linked list using c#? examples have found far quite overdone.
a linked list, @ core bunch of nodes linked together.
so, need start simple node class:
public class node {     public node next;     public object data; }   then linked list have member 1 node representing head (start) of list:
public class linkedlist {     private node head; }   then need add functionality list adding methods. involve sort of traversal along of nodes.
public void printallnodes() {     node cur = head;     while (cur.next != null)      {         console.writeline(cur.data);         cur = cur.next;     } }   also, inserting new data common operation:
public void add(object data) {     node toadd = new node();     toadd.data = data;     node current = head;     // traverse nodes (see print nodes method example)     current.next = toadd; }   this should provide starting point........
Comments
Post a Comment