add c++11 (#87)
* binary search c++ * selection sort c++11 * c++ recursive countdown * c++ recursion * c++ quicksort * rename folder names to c++11 * add another version of binary_search function * c++11 hash tables * c++11 breadth-first search
This commit is contained in:
18
03_recursion/c++11/01_countdown.cpp
Normal file
18
03_recursion/c++11/01_countdown.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
void countdown(const int& i) {
|
||||
cout << i << endl;
|
||||
|
||||
// base case
|
||||
if (i <= 0) return;\
|
||||
|
||||
// recursive case
|
||||
countdown(i - 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
countdown(5);
|
||||
}
|
||||
27
03_recursion/c++11/02_greet.cpp
Normal file
27
03_recursion/c++11/02_greet.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
void greet2(std::string name) {
|
||||
cout << "How are you, " + name + "?" << endl;
|
||||
}
|
||||
|
||||
void bye() {
|
||||
cout << "Ok, bye!" << endl;
|
||||
}
|
||||
|
||||
|
||||
void greet(std::string name) {
|
||||
cout << "Hello, " + name + "!" << endl;
|
||||
greet2(name);
|
||||
cout << "Getting ready to say bye..." << endl;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
greet("Adit");
|
||||
|
||||
return 0;
|
||||
}
|
||||
13
03_recursion/c++11/03_factorial.cpp
Normal file
13
03_recursion/c++11/03_factorial.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int fact(const int& x) {
|
||||
if (x == 1) return 1;
|
||||
return fact(x-1) * x;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cout << fact(5) << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user