summaryrefslogtreecommitdiff
path: root/algo1w3/main.cpp
blob: 38a88b1dba3905c4425c35abfa6699c3760921ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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();
}