summaryrefslogtreecommitdiff
path: root/algo1w3/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'algo1w3/main.cpp')
-rw-r--r--algo1w3/main.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/algo1w3/main.cpp b/algo1w3/main.cpp
new file mode 100644
index 0000000..38a88b1
--- /dev/null
+++ b/algo1w3/main.cpp
@@ -0,0 +1,83 @@
+// Week3Deel1.cpp : Defines the entry point for the console application.
+//
+
+#include "NAWLinkedList.h"
+#include "IntLinkedList.h"
+
+#include "NAW.h"
+#include "NAWLink.h"
+
+#include <chrono>
+#include <iostream>
+#include <sstream>
+
+void testNAWLinkedList();
+void testintLinkedList();
+
+int main() {
+ testNAWLinkedList();
+ testintLinkedList();
+
+ return 0;
+}
+
+void testNAWLinkedList() {
+ NAWLinkedList linkedList;
+ NAWLink *link1, *link2;
+
+ for (int n = 0; n < 20; n++) {
+ std::stringstream naam, adres, plaats;
+
+ naam << "avans " << n + 1;
+ adres << "onderwijsboulevard " << n + 1;
+ plaats << "den bosch " << n + 1;
+
+ linkedList.addToStart({ naam.str(), adres.str(), plaats.str() });
+ }
+
+ linkedList.showAll();
+
+ std::stringstream naam, adres, plaats;
+
+ naam << "avans " << 7;
+ adres << "onderwijsboulevard " << 7;
+ plaats << "den bosch " << 7;
+
+ link1 = linkedList.search({ naam.str(), adres.str(), plaats.str() });
+ link2 = linkedList.removeFirst({ naam.str(), adres.str(), plaats.str() });
+
+ std::cout << link1 << " =?= " << link2 << std::endl;
+}
+
+void testintLinkedList() {
+ IntLinkedList linkedList;
+ std::chrono::steady_clock::time_point start, end;
+
+ for (int n = 20; n > 0; n--) {
+ if ((n & 1) == 0)
+ linkedList.addToStart(n+10);
+ else
+ linkedList.addToStart(n);
+ }
+
+ std::cout << "link at position 7: " << linkedList.getAt(7) << std::endl;
+ std::cout << "link at position 37: " << linkedList.getAt(37) << std::endl;
+
+ linkedList.setAt( 7, 8);
+ linkedList.setAt(37, 38);
+
+ std::cout << "link at position 7: " << linkedList.getAt(7) << std::endl;
+ std::cout << "link at position 37: " << linkedList.getAt(37) << std::endl;
+
+ std::cout << linkedList.length1() << " =?= " << linkedList.length2() << std::endl;
+
+ linkedList.showAll();
+
+ start = std::chrono::steady_clock::now();
+ linkedList.bubbleSort(); for (int n=0; n<(1<<25); n++);
+ end = std::chrono::steady_clock::now();
+
+ std::cout << "duration = " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << " us" << std::endl;
+
+ linkedList.showAll();
+}