Skip to content

Commit a670025

Browse files
Revert "Merge branch 'master' into cstdint"
This reverts commit aba74d8, reversing changes made to d40099a.
1 parent aba74d8 commit a670025

File tree

8 files changed

+72
-879
lines changed

8 files changed

+72
-879
lines changed

DIRECTORY.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161

162162
## Greedy Algorithms
163163
* [Boruvkas Minimum Spanning Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/boruvkas_minimum_spanning_tree.cpp)
164-
* [Digit Separation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/digit_separation.cpp)
165164
* [Dijkstra](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/dijkstra.cpp)
166165
* [Gale Shapley](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/gale_shapley.cpp)
167166
* [Huffman](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/huffman.cpp)
@@ -301,7 +300,6 @@
301300
* [Iterative Tree Traversals](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/iterative_tree_traversals.cpp)
302301
* [Kadanes3](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/kadanes3.cpp)
303302
* [Kelvin To Celsius](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/kelvin_to_celsius.cpp)
304-
* [Lfu Cache](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/lfu_cache.cpp)
305303
* [Lru Cache](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/lru_cache.cpp)
306304
* [Matrix Exponentiation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/matrix_exponentiation.cpp)
307305
* [Palindrome Of Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/palindrome_of_number.cpp)
@@ -371,7 +369,6 @@
371369
* [Gnome Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/gnome_sort.cpp)
372370
* [Heap Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/heap_sort.cpp)
373371
* [Insertion Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/insertion_sort.cpp)
374-
* [Insertion Sort Recursive](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/insertion_sort_recursive.cpp)
375372
* [Library Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/library_sort.cpp)
376373
* [Merge Insertion Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/merge_insertion_sort.cpp)
377374
* [Merge Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/merge_sort.cpp)

greedy_algorithms/digit_separation.cpp

Lines changed: 0 additions & 142 deletions
This file was deleted.

math/area.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,6 @@ template <typename T>
109109
T cylinder_surface_area(T radius, T height) {
110110
return 2 * M_PI * radius * height + 2 * M_PI * pow(radius, 2);
111111
}
112-
113-
/**
114-
* @brief surface area of a [hemi-sphere](https://en.wikipedia.org/wiki/Surface_area) ( 3 *
115-
* pi * r^2)
116-
* @param radius is the radius of the hemi-sphere
117-
* @tparam T datatype of radius
118-
* @returns surface area of the hemi-sphere
119-
*/
120-
template <typename T>
121-
T hemi_sphere_surface_area(T radius) {
122-
return 3 * M_PI * pow(radius, 2);
123-
}
124112
} // namespace math
125113

126114
/**
@@ -279,18 +267,6 @@ static void test() {
279267
std::cout << "Output: " << double_area << std::endl;
280268
assert(double_area == double_expected);
281269
std::cout << "TEST PASSED" << std::endl << std::endl;
282-
283-
// 11th test
284-
double_radius = 10.0;
285-
double_expected = 942.4777960769379;
286-
double_area = math::hemi_sphere_surface_area(double_radius);
287-
288-
std::cout << "SURFACE AREA OF A HEMI-SPHERE" << std::endl;
289-
std::cout << "Input Radius: " << double_radius << std::endl;
290-
std::cout << "Expected Output: " << double_expected << std::endl;
291-
std::cout << "Output: " << double_area << std::endl;
292-
assert(double_area == double_expected);
293-
std::cout << "TEST PASSED" << std::endl << std::endl;
294270
}
295271

296272
/**

math/fibonacci.cpp

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,68 @@
11
/**
22
* @file
3-
* @brief n-th [Fibonacci
4-
* number](https://en.wikipedia.org/wiki/Fibonacci_sequence).
3+
* @brief Generate fibonacci sequence
54
*
6-
* @details
7-
* Naive recursive implementation to calculate the n-th Fibonacci number.
5+
* Calculate the the value on Fibonacci's sequence given an
6+
* integer as input.
87
* \f[\text{fib}(n) = \text{fib}(n-1) + \text{fib}(n-2)\f]
98
*
109
* @see fibonacci_large.cpp, fibonacci_fast.cpp, string_fibonacci.cpp
1110
*/
12-
13-
#include <cstdint> /// for std::uint64_t
14-
#include <cassert> /// for assert
15-
#include <iostream> /// for IO operations
16-
17-
/**
18-
* @namespace math
19-
* @brief Math algorithms
20-
*/
21-
namespace math {
11+
#include <cassert>
12+
#include <cstdint>
13+
#include <iostream>
2214
/**
23-
* @namespace fibonacci
24-
* @brief Functions for Fibonacci sequence
25-
*/
26-
namespace fibonacci {
27-
/**
28-
* @brief Function to compute the n-th Fibonacci number
29-
* @param n the index of the Fibonacci number
30-
* @returns n-th element of the Fibonacci's sequence
15+
* Recursively compute sequences
16+
* @param n input
17+
* @returns n-th element of the Fbinacci's sequence
3118
*/
3219
uint64_t fibonacci(uint64_t n) {
33-
// If the input is 0 or 1 just return the same (Base Case)
34-
// This will set the first 2 values of the sequence
20+
/* If the input is 0 or 1 just return the same
21+
This will set the first 2 values of the sequence */
3522
if (n <= 1) {
3623
return n;
3724
}
3825

39-
// Add the preceding 2 values of the sequence to get next
26+
/* Add the last 2 values of the sequence to get next */
4027
return fibonacci(n - 1) + fibonacci(n - 2);
4128
}
42-
} // namespace fibonacci
43-
} // namespace math
4429

4530
/**
46-
* @brief Self-test implementation
31+
* Function for testing the fibonacci() function with a few
32+
* test cases and assert statement.
4733
* @returns `void`
4834
*/
4935
static void test() {
50-
assert(math::fibonacci::fibonacci(0) == 0);
51-
assert(math::fibonacci::fibonacci(1) == 1);
52-
assert(math::fibonacci::fibonacci(2) == 1);
53-
assert(math::fibonacci::fibonacci(3) == 2);
54-
assert(math::fibonacci::fibonacci(4) == 3);
55-
assert(math::fibonacci::fibonacci(15) == 610);
56-
assert(math::fibonacci::fibonacci(20) == 6765);
57-
std::cout << "All tests have passed successfully!\n";
36+
uint64_t test_case_1 = fibonacci(0);
37+
assert(test_case_1 == 0);
38+
std::cout << "Passed Test 1!" << std::endl;
39+
40+
uint64_t test_case_2 = fibonacci(1);
41+
assert(test_case_2 == 1);
42+
std::cout << "Passed Test 2!" << std::endl;
43+
44+
uint64_t test_case_3 = fibonacci(2);
45+
assert(test_case_3 == 1);
46+
std::cout << "Passed Test 3!" << std::endl;
47+
48+
uint64_t test_case_4 = fibonacci(3);
49+
assert(test_case_4 == 2);
50+
std::cout << "Passed Test 4!" << std::endl;
51+
52+
uint64_t test_case_5 = fibonacci(4);
53+
assert(test_case_5 == 3);
54+
std::cout << "Passed Test 5!" << std::endl;
55+
56+
uint64_t test_case_6 = fibonacci(15);
57+
assert(test_case_6 == 610);
58+
std::cout << "Passed Test 6!" << std::endl << std::endl;
5859
}
5960

60-
/**
61-
* @brief Main function
62-
* @returns 0 on exit
63-
*/
61+
/// Main function
6462
int main() {
65-
test(); // run self-test implementations
66-
return 0;
63+
test();
64+
int n = 0;
65+
std::cin >> n;
66+
assert(n >= 0);
67+
std::cout << "F(" << n << ")= " << fibonacci(n) << std::endl;
6768
}

0 commit comments

Comments
 (0)