How to write a program that contains a binary search in C++ , an array list of s
ID: 3634756 • Letter: H
Question
How to write a program that contains a binary search in C++ , an array list of set integers, asks for user input and takes that input to search the arraylist. If user input is in arraylist then the program delivers a message "present" and if not program delivers message "unavailable" .Explanation / Answer
Vector FindShortestPath(nodeT *start, nodeT *finish) { Vector path; Queue queue; Map fixed; while (start != finish) { if (!fixed.containsKey(start->name)) { fixed.put(start->name, TotalPathDistance(path)); foreach (arcT *arc in start->arcs) { if (!fixed.containsKey(arc->finish->name)) { Vector newPath = path; newPath.add(arc); queue.enqueue(newPath, TotalPathDistance(newPath)); } } } if (queue.isEmpty()) return Vector(); path = queue.dequeue(); start = path[path.size() - 1]->finish; } return path; } /* * Function: TotalPathDistance * Usage: double distance = TotalPathDistance(path); * ------------------------------------------------- * Returns the total distance along the path. */ double TotalPathDistance(Vector path) { double distance = 0; foreach (arcT *arc in path) { distance += arc->cost; } return distance; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.