//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Sort list. </summary> /// /// <remarks> Galarist, 18/09/2018. </remarks> //////////////////////////////////////////////////////////////////////////////////////////////////// public void SortList() { //sorts the list by the equation result LinkListNode current = HeadNode; for (LinkListNode i = current; i.GetNext() != null; i = i.GetNext()) { for (LinkListNode j = i.GetNext(); j != null; j = j.GetNext()) { if (i.GetMyValue().ANumber > j.GetMyValue().ANumber) { var Temp = j.GetMyValue(); j.SetMyValue(i.GetMyValue()); i.SetMyValue(Temp); } } } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Binary search. </summary> /// /// <remarks> Galarist, 18/09/2018. </remarks> /// /// <param name="searchValue"> The search value. </param> /// /// <returns> An int. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public int BinarySearch(LinkListNode searchValue) { //sorts the link list by result SortList(); LinkListNode current = HeadNode; ArrayList myTempList = new ArrayList(); for (LinkListNode i = current; i != null; i = i.GetNext()) { myTempList.Add(i.GetMyValue()); } //returns the integer value of where the node sits in the node list return(myTempList.BinarySearch(searchValue)); }