private static NodeOWC GetLastNode() { NodeOWC p = head; while (p.next != null) { p = p.next; } return(p); }
public static void Print() { NodeOWC p = head; do { Console.WriteLine($"-> {p.data}"); p = p.next; } while (p.next != null); Console.WriteLine($"{p.data}"); }
public static void Insert(int insertPosition, NodeOWC newNode) { NodeOWC p = head; int i = 0; while (p.next != null && i < (insertPosition - 1)) { p = p.next; i++; } newNode.next = p.next; p.next = newNode; }
public static void Add(string data) { NodeOWC newNode = new NodeOWC(data); if (head == null) { head = newNode; return; } NodeOWC lastNode = GetLastNode(); lastNode.next = newNode; tail = newNode; }
public static void Remove(int removePosition) { NodeOWC p = head; int i = 0; while (p.next != null && i < (removePosition - 1)) { p = p.next; i++; } NodeOWC temp = p.next; p.next = p.next.next; temp.next = null; }