public TwoWayLinkedList GetRoute(TwoWayLinkedList chosenCities, City startPoint) { /* * LIST chosenCities SHOULDN'T CONTAIN STARTPOINT */ City currentCity = startPoint; int currentCityIndex = 0; int[] distanceFromCurrentCity; City nearestNeighbour; int nearestNeighbourIndex; TwoWayLinkedList route = new TwoWayLinkedList(); while (chosenCities.GetSize() != 0) { currentCityIndex = FindCurrentCityIndex(currentCity); distanceFromCurrentCity = Dijkstra(CitiesInfo.Distances, currentCityIndex); nearestNeighbourIndex = MinDistanceIndex(distanceFromCurrentCity, chosenCities); nearestNeighbour = CitiesInfo.Cities[nearestNeighbourIndex]; route.Concatenation(intermediateCities[nearestNeighbourIndex]); route.PushLast(nearestNeighbour); chosenCities.DelMidle(chosenCities.IndexOf(nearestNeighbour)); currentCity = nearestNeighbour; } return(ClearRepetitions(route)); }
public void QuickSortPeopleYoungerTwenty() { Node pivot = this.last; //Node first = this.head; if (this.Size > 1) { TwoWayLinkedList listMorePivot = new TwoWayLinkedList(); TwoWayLinkedList listLessPivot = new TwoWayLinkedList(); foreach (City city in this) { if (city == this.last.data) { break; } if (city.AmountPeople >= pivot.data.AmountPeopleYoungerTwenty) { listMorePivot.PushFirst(city); } else { listLessPivot.PushFirst(city); } } listMorePivot.QuickSortPeopleYoungerTwenty(); listLessPivot.QuickSortPeopleYoungerTwenty(); listLessPivot.PushLast(pivot.data); listLessPivot.Concatenation(listMorePivot); this.head = listLessPivot.head; this.last = listLessPivot.last; // присваевается концу списка меньших за опорный ибо после конкатенации в списке меньших за опроный // находится уже сума списков больших и меньших за опроных, а список больших остаеться быть таким же и иногода он может быть пустым. } }