Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- selection_sort(int a, int b){
- if(a == b+1){
- //do nothing
- }else{
- i = minIndex(arr, a, b); //minIndex finds minimum value of 2 index's an array
- if(i != a)
- swap(arr, i, a);
- selection_sort(a+1, b);
- }
- }
- void countdown(int t) {
- if (t <= 1) return;
- printf("%dn", t);
- countdown(t - 1);
- }
- int factorial(int n) {
- if (n <= 1) return 1;
- return n * factorial(n - 1);
- }
- int factorial(int n, int product = 1) {
- if (n <= 1) return product;
- return factorial(n - 1, product * n);
- }
- selection_sort(int a, int b){
- tail_call:
- if(a == b+1){
- //do nothing
- }else{
- i = minIndex(arr, a, b);
- if(i != a)
- swap(arr, i, a);
- // tweak the variables so the next iteration sees (a+1, b)
- a += 1;
- goto tail_call;
- }
- }
- selection_sort(int a, int b){
- tail_call:
- if(a != b+1){
- i = minIndex(arr, a, b);
- if(i != a)
- swap(arr, i, a);
- // tweak the variables so the next iteration sees (a+1, b)
- a += 1;
- goto tail_call;
- }
- }
- loop:
- if (condition) {
- ...magic...
- goto loop;
- }
- while (condition) {
- ...magic...
- }
- selection_sort(int a, int b){
- while (a != b+1) {
- int i = minIndex(arr, a, b);
- if(i != a)
- swap(arr, i, a);
- a += 1;
- }
- }
- selection_sort(){
- int firstIndex = 0;
- int lastIndex = arr.length;
- while(firstIndex < lastIndex) {
- int i = minIndex(arr, firstIndex, lastIndex);
- if(i != a) {
- swap(entries, i, firstIndex);
- }
- firstIndex ++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement