public void Add(int index, BoatNode b) { if (index < 0) { throw new IndexOutOfRangeException("Index cannot be less than zero"); } if (index > count) { index = count; } //get head BoatNode current = Head; if (Count == 0 || index == 0) { Head = b; } else { for (int i = 0; i < index - 1; i++) { current = current.GetNext(); } // BoatNode nextBoat = new Software_Implementation_Project.BoatNode(b, current.GetNext()); current.SetNext(b); } Count = Count + 1;; }
public void DeleteBoat(int index) { if (index < 0) { throw new IndexOutOfRangeException("Index for delete boat is out of range"); } BoatNode currentBoat = head; if (index > Count) { index = Count - 1; } if (index == 0) { head = currentBoat.GetNext(); } else { for (int i = 0; i < index - 1; i++) { currentBoat = currentBoat.GetNext(); } currentBoat.SetNext(currentBoat.GetNext().GetNext()); } count--; }
public void ClearAllMarinaItems() { Head = new BoatNode(); Head.SetNext(null); count = 0; }