(*)~changed up makefile recipes, cleaned up README
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.out
|
||||||
|
*.fasl
|
||||||
13
Makefile
13
Makefile
@@ -1,11 +1,14 @@
|
|||||||
CC=clang++
|
CC=clang++
|
||||||
CFLAGS=-pedantic -Wall -ggdb
|
CFLAGS=-pedantic -Wall -ggdb -fsanitize=address
|
||||||
VFLAGS=--show-leak-kinds=all --leak-check=full
|
VFLAGS=--show-leak-kinds=all --leak-check=full
|
||||||
OUT=
|
OUT=
|
||||||
|
|
||||||
$(OUT): $(OUT).cpp
|
$(OUT).out: $(OUT).cpp
|
||||||
$(CC) $(CFLAGS) $^ -o $@
|
$(CC) $(CFLAGS) $^ -o $@
|
||||||
|
|
||||||
.PHONY: memcheck
|
.PHONY: run
|
||||||
memcheck: $(OUT)
|
run: $(OUT).out
|
||||||
valgrind $(VFLAGS) ./$^;
|
./$^
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
rm -v *.out;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#+title: Algorithms
|
#+title: Algorithms
|
||||||
#+author: Aryadev Chavali
|
#+author: Aryadev Chavali
|
||||||
|
|
||||||
Common algorithms in C/C++/Python depending on which one is the
|
Common algorithms and data structures, written in any language I
|
||||||
nicest/makes the most sense to use. This will include random maths
|
want. Currently there's an implementation for binary trees and singly
|
||||||
stuff as well, such as making supporting mechanisms for, say, the use
|
linked lists in C++.
|
||||||
of group semantics.
|
|
||||||
|
|||||||
27
list.cpp
27
list.cpp
@@ -107,26 +107,33 @@ int main(void)
|
|||||||
std::cout << lst << std::endl;
|
std::cout << lst << std::endl;
|
||||||
puts("Reverse list again...");
|
puts("Reverse list again...");
|
||||||
printf("Map list with f(x) = 2x: ");
|
printf("Map list with f(x) = 2x: ");
|
||||||
map<int, int>(lst = reverse(lst), [](int x) {
|
map<int, int>(lst = reverse(lst),
|
||||||
return x * 2;
|
[](int x)
|
||||||
});
|
{
|
||||||
|
return x * 2;
|
||||||
|
});
|
||||||
std::cout << lst << std::endl;
|
std::cout << lst << std::endl;
|
||||||
puts("Reverse map...");
|
puts("Reverse map...");
|
||||||
map<int, int>(lst, [](int x) {
|
map<int, int>(lst,
|
||||||
return x / 2;
|
[](int x)
|
||||||
});
|
{
|
||||||
|
return x / 2;
|
||||||
|
});
|
||||||
printf("Sum all numbers in list: ");
|
printf("Sum all numbers in list: ");
|
||||||
std::cout << reduce<int>(
|
std::cout << reduce<int>(
|
||||||
lst,
|
lst,
|
||||||
[](int a, int b) {
|
[](int a, int b)
|
||||||
|
{
|
||||||
return a + b;
|
return a + b;
|
||||||
},
|
},
|
||||||
0)
|
0)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
printf("Print all even numbers 1..10: ");
|
printf("Print all even numbers 1..10: ");
|
||||||
auto evens = filter<int>(lst, [](int a) {
|
auto evens = filter<int>(lst,
|
||||||
return a % 2 == 0;
|
[](int a)
|
||||||
});
|
{
|
||||||
|
return a % 2 == 0;
|
||||||
|
});
|
||||||
std::cout << evens << std::endl;
|
std::cout << evens << std::endl;
|
||||||
delete lst;
|
delete lst;
|
||||||
delete evens;
|
delete evens;
|
||||||
|
|||||||
Reference in New Issue
Block a user