/// <summary> /// comparing method /// </summary> /// <param name="other"></param> /// <returns></returns> public int CompareTo(ResidentNode other) { if (resident.Surname.CompareTo(other.resident.Surname) == 0 && resident.Address.CompareTo(other.resident.Address) == 0) { return(resident.Name.CompareTo(other.resident.Name)); } else { return(resident.Surname.CompareTo(other.resident.Surname)); } }
/// <summary> /// method used to get count of the linked list /// </summary> /// <returns></returns> public int getCount() { ResidentNode temp = Head; int count = 0; while (temp != null) { count++; temp = temp.next; } return(count); }
/// <summary> /// method to put data /// </summary> /// <param name="resident"></param> public void PutData(Resident resident) { var temp = new ResidentNode(resident, null); if (Head != null) { Tail.next = temp; Tail = temp; } else { Head = temp; Tail = temp; } }
/// <summary> /// method to remove the node in the list /// </summary> /// <param name="resident"></param> public void Remove(ResidentNode resident) { ResidentNode temp = Head; ResidentNode prev = null; if (temp != null && temp.Get() == resident.Get()) { Head = temp.next; return; } while (temp != null && temp.Get() != resident.Get()) { prev = temp; temp = temp.next; } if (temp == null) { return; } prev.next = temp.next; }
/// <summary> /// method to set temp node to the next node /// </summary> public void Next() { Temp = Temp.next; }
/// <summary> /// method to set temp node to the tail /// </summary> public void Ending() { Head = Tail; }
/// <summary> /// method to set temp node to the head /// </summary> public void Beginning() { Temp = Head; }
/// <summary> /// Constructor to create linkedlist /// </summary> public ResidentList() { this.Head = null; this.Tail = null; }
/// <summary> /// constructor /// </summary> /// <param name="resident"></param> /// <param name="residentnode"></param> public ResidentNode(Resident resident, ResidentNode residentnode) { this.resident = resident; next = residentnode; }