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
| int fib2(int n){ | |
| if(n == 0) | |
| return 0; | |
| if(n == 1 || n == 2) | |
| return 1; | |
| return fib2(n-2) + fib2(n-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
| int fib(int nElem){ | |
| int *arr = new int[nElem+1]; | |
| arr[0] = 0; | |
| arr[1] = 1; | |
| for(int i = 2; i <= nElem; i++){ | |
| arr[i] = arr[i-1] + arr[i-2]; | |
| } | |
| return arr[nElem]; | |
| } |
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
| int fibSimple(int elem){ | |
| if(elem < 0){ | |
| return 0; | |
| } | |
| if(elem == 0){ | |
| return 0; | |
| } | |
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
| bool isPrime(int number){ | |
| for(int i = 2; i <= sqrt((double)number); i++){ | |
| if(number%i == 0) | |
| return false; | |
| } | |
| return true; | |
| } |
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 selectionSort(int *arr, int length){ | |
| for(int i = 0; i < length; i++){ | |
| int minIndex = i; | |
| for(int j = i + 1; j < length; j++){ | |
| if(arr[minIndex] > arr[j]){ | |
| minIndex = j; | |
| } | |
| } | |
| if(minIndex != i){ | |
| int temp = arr[minIndex]; |
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 bubbleSort(int *arr, int length){ | |
| for(int i = 0; i < length; i++){ | |
| for(int j = 0; j < length - 1 - i; j++){ | |
| if(arr[j] > arr[j+1]){ | |
| int temp = arr[j+1]; | |
| arr[j+1] = arr[j]; | |
| arr[j] = temp; | |
| } | |
| } | |
| } |
NewerOlder