diff options
Diffstat (limited to 'algo1w3/main.cpp')
-rw-r--r-- | algo1w3/main.cpp | 90 |
1 files changed, 32 insertions, 58 deletions
diff --git a/algo1w3/main.cpp b/algo1w3/main.cpp index 38a88b1..8f89afa 100644 --- a/algo1w3/main.cpp +++ b/algo1w3/main.cpp @@ -1,83 +1,57 @@ -// Week3Deel1.cpp : Defines the entry point for the console application. -// - -#include "NAWLinkedList.h" -#include "IntLinkedList.h" - -#include "NAW.h" -#include "NAWLink.h" +#include "IntDoubleLinkedList.h" +#include <cstdlib> +#include <ctime> #include <chrono> #include <iostream> -#include <sstream> -void testNAWLinkedList(); -void testintLinkedList(); +void testVraag1(); +void testVraag2(); int main() { - testNAWLinkedList(); - testintLinkedList(); + testVraag1(); + testVraag2(); return 0; } -void testNAWLinkedList() { - NAWLinkedList linkedList; - NAWLink *link1, *link2; - - for (int n = 0; n < 20; n++) { - std::stringstream naam, adres, plaats; +void testVraag1() { + const int SIZE = 20; + IntDoubleLinkedList linkedList; + std::chrono::steady_clock::time_point start, end; - naam << "avans " << n + 1; - adres << "onderwijsboulevard " << n + 1; - plaats << "den bosch " << n + 1; + std::srand(unsigned(time(nullptr))); - linkedList.addToStart({ naam.str(), adres.str(), plaats.str() }); + for (int n = 0; n < SIZE; n++) { + if ((n&1) == 0) + linkedList.insertAtStart(std::rand()); + else + linkedList.insertAtEnd(std::rand()); } - linkedList.showAll(); - - std::stringstream naam, adres, plaats; - - naam << "avans " << 7; - adres << "onderwijsboulevard " << 7; - plaats << "den bosch " << 7; + start = std::chrono::steady_clock::now(); + linkedList.rapidBubbleSort();// for (int n=0; n<(1<<25); n++); + end = std::chrono::steady_clock::now(); - link1 = linkedList.search({ naam.str(), adres.str(), plaats.str() }); - link2 = linkedList.removeFirst({ naam.str(), adres.str(), plaats.str() }); + std::cout << "duration = " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << " us" << std::endl; - std::cout << link1 << " =?= " << link2 << std::endl; + linkedList.showAll(); } -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; +void testVraag2() { + IntDoubleLinkedList linkedList; - linkedList.setAt( 7, 8); - linkedList.setAt(37, 38); + for (int n = 0; n < 20; n++) + linkedList.insertAction(n); - std::cout << "link at position 7: " << linkedList.getAt(7) << std::endl; - std::cout << "link at position 37: " << linkedList.getAt(37) << std::endl; + for (int n = 0; n < 10; n++) + std::cout << linkedList.undo() << std::endl; - std::cout << linkedList.length1() << " =?= " << linkedList.length2() << std::endl; + for (int n = 0; n < 5; n++) + std::cout << linkedList.redo() << 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.insertAction(100); + std::cout << " ----- " << std::endl; linkedList.showAll(); } |