public void AddAtIndex(int index, int val) { if (index < 0 || index > Count) { return; } if (index == 0) { AddAtHead(val); return; } if (index == Count) { AddAtTail(val); return; } var nNode = new Nodee(val); var temp = Head; var i = 0; while (i < index - 1) { i++; temp = temp.Next; } nNode.Next = temp.Next; temp.Next = nNode; Count++; }
public void AddAtTail(int val) { if (Count == 0) { AddAtHead(val); } else { var lstNode = GetLastNodee(); var temp = new Nodee(val); lstNode.Next = temp; Count++; } }
public void AddAtHead(int val) { var temp = new Nodee(val); if (Head == null) { Head = temp; } else { temp.Next = Head; Head = temp; } Count++; }