This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Quicksort(Vector<int> &v, int start, int stop) { | |
| if(stop > start) { | |
| int pivot = Partition(v, start, stop); | |
| Quicksort(v, start, pivot-1); | |
| Quicksort(v, pivot+1, stop); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void MergeSort(Vector<int> &v){ | |
| if (v.size() > 1) { | |
| int n1 = v.size()/2; | |
| int n2 = v.size() - n1; | |
| Vector<int> left = Copy(v, 0, n1); Vector<int> right = Copy(v, n1, n2); MergeSort(left); | |
| MergeSort(right); | |
| Merge(v, left, right); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void recSubsets(String soFar, String rest) { | |
| if (rest.equals("")) { | |
| System.out.println(soFar); | |
| } else { | |
| recSubsets(soFar + rest.charAt(0), rest.substring(1)); | |
| recSubsets(soFar, rest.substring(1)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void recPermute(String soFar, String rest) { | |
| if (rest.equals( "" )) { | |
| System.out.println( soFar ); | |
| } else { | |
| for (int i = 0; i < rest.length(); i++) { | |
| String next = soFar + rest.charAt(i); | |
| String remaining = rest.substring(0, i) + rest.substring(i+1); | |
| recPermute(next, remaining); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| boolean solve(configuration conf) { | |
| if (no more choices) | |
| return (conf is goal state); | |
| for (all available choices) { | |
| try one choice c; | |
| ok = solve(conf with choice c made); | |
| if (ok) | |
| return true; | |
| else | |
| unmake choice c; |
NewerOlder