aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile13
-rw-r--r--README.org7
-rw-r--r--list.cpp27
4 files changed, 30 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3a4a082
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.out
+*.fasl \ No newline at end of file
diff --git a/Makefile b/Makefile
index 5a4e524..e8e6753 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,14 @@
CC=clang++
-CFLAGS=-pedantic -Wall -ggdb
+CFLAGS=-pedantic -Wall -ggdb -fsanitize=address
VFLAGS=--show-leak-kinds=all --leak-check=full
OUT=
-$(OUT): $(OUT).cpp
+$(OUT).out: $(OUT).cpp
$(CC) $(CFLAGS) $^ -o $@
-.PHONY: memcheck
-memcheck: $(OUT)
- valgrind $(VFLAGS) ./$^;
+.PHONY: run
+run: $(OUT).out
+ ./$^
+
+.PHONY: clean
+ rm -v *.out;
diff --git a/README.org b/README.org
index 6a272af..d8abb2b 100644
--- a/README.org
+++ b/README.org
@@ -1,7 +1,6 @@
#+title: Algorithms
#+author: Aryadev Chavali
-Common algorithms in C/C++/Python depending on which one is the
-nicest/makes the most sense to use. This will include random maths
-stuff as well, such as making supporting mechanisms for, say, the use
-of group semantics.
+Common algorithms and data structures, written in any language I
+want. Currently there's an implementation for binary trees and singly
+linked lists in C++.
diff --git a/list.cpp b/list.cpp
index 8697d06..aa04294 100644
--- a/list.cpp
+++ b/list.cpp
@@ -107,26 +107,33 @@ int main(void)
std::cout << lst << std::endl;
puts("Reverse list again...");
printf("Map list with f(x) = 2x: ");
- map<int, int>(lst = reverse(lst), [](int x) {
- return x * 2;
- });
+ map<int, int>(lst = reverse(lst),
+ [](int x)
+ {
+ return x * 2;
+ });
std::cout << lst << std::endl;
puts("Reverse map...");
- map<int, int>(lst, [](int x) {
- return x / 2;
- });
+ map<int, int>(lst,
+ [](int x)
+ {
+ return x / 2;
+ });
printf("Sum all numbers in list: ");
std::cout << reduce<int>(
lst,
- [](int a, int b) {
+ [](int a, int b)
+ {
return a + b;
},
0)
<< std::endl;
printf("Print all even numbers 1..10: ");
- auto evens = filter<int>(lst, [](int a) {
- return a % 2 == 0;
- });
+ auto evens = filter<int>(lst,
+ [](int a)
+ {
+ return a % 2 == 0;
+ });
std::cout << evens << std::endl;
delete lst;
delete evens;