public IEnumerable <T> Dijkstras(Vertex <T> start, Vertex <T> end) { //1. foreach (Vertex <T> vertex in Vertices) { vertex.visited = false; vertex.startDistance = double.PositiveInfinity; vertex.founder = null; } //2. start.startDistance = 0; TreeHeap <Vertex <T> > heap = new TreeHeap <Vertex <T> >(true); heap.Insert(start); //6. while (heap.Count > 0) { //3. var yeet = heap.Pop(); yeet.visited = true; //4. foreach (var neighbor in yeet.Neighbors) { if (neighbor.EndingPoint.open) { double tentative = yeet.startDistance + neighbor.Distance; if (tentative < neighbor.EndingPoint.startDistance) { neighbor.EndingPoint.startDistance = tentative; neighbor.EndingPoint.founder = yeet; neighbor.EndingPoint.visited = false; } //5. if (neighbor.EndingPoint.visited == false && !heap.Contains(neighbor.EndingPoint)) { heap.Insert(neighbor.EndingPoint); } } } } //7. Stack <T> yuut = new Stack <T>(); var yoot = end; while (yoot != start) { yuut.Push(yoot.value); yoot = yoot.founder; } yuut.Push(start.value); return(yuut); }
public static List <T> YEETSort(List <T> yeet) { TreeHeap <T> tree = new TreeHeap <T>(true); for (int i = 0; i < yeet.Count; i++) { tree.Insert(yeet[i]); } List <T> yeeter = new List <T>(); for (int i = 0; i < yeet.Count; i++) { yeeter.Add(tree.Pop()); } return(yeeter); }