├── Debug
└── Problem3.pdb
├── Problem3.sln
├── Problem3
├── Debug
│ ├── Problem3.exe.recipe
│ ├── Problem3.tlog
│ │ ├── CL.command.1.tlog
│ │ ├── CL.read.1.tlog
│ │ ├── CL.write.1.tlog
│ │ ├── Problem3.lastbuildstate
│ │ ├── link-cvtres.read.1.tlog
│ │ ├── link-cvtres.write.1.tlog
│ │ ├── link-rc.read.1.tlog
│ │ ├── link-rc.write.1.tlog
│ │ ├── link.command.1.tlog
│ │ ├── link.read.1.tlog
│ │ ├── link.write.1.tlog
│ │ └── unsuccessfulbuild
│ ├── vc143.idb
│ └── vc143.pdb
├── Problem3.cpp
├── Problem3.vcxproj
├── Problem3.vcxproj.filters
├── Problem3.vcxproj.user
├── Tree.cpp
├── TreeADT.h
├── TreeWrapper.h
└── x64
│ └── Debug
│ ├── Problem3.exe.recipe
│ ├── Problem3.ilk
│ ├── Problem3.log
│ ├── Problem3.tlog
│ ├── CL.command.1.tlog
│ ├── CL.read.1.tlog
│ ├── CL.write.1.tlog
│ ├── Problem3.lastbuildstate
│ ├── link.command.1.tlog
│ ├── link.read.1.tlog
│ └── link.write.1.tlog
│ ├── tree.obj.enc
│ ├── vc143.idb
│ └── vc143.pdb
├── problem1
├── insertionSort.cpp
└── main.cpp
├── problem2
├── Adversary.cpp
├── BFS.cpp
├── Graph.cpp
├── GraphADT.h
└── main.cpp
└── x64
└── Debug
└── Problem3.pdb
/Debug/Problem3.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Debug/Problem3.pdb
--------------------------------------------------------------------------------
/Problem3.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.4.33110.190
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Problem3", "Problem3\Problem3.vcxproj", "{481AEBC6-802B-4C8D-8B5B-E3BB3BE6C97B}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {481AEBC6-802B-4C8D-8B5B-E3BB3BE6C97B}.Debug|x64.ActiveCfg = Debug|x64
17 | {481AEBC6-802B-4C8D-8B5B-E3BB3BE6C97B}.Debug|x64.Build.0 = Debug|x64
18 | {481AEBC6-802B-4C8D-8B5B-E3BB3BE6C97B}.Debug|x86.ActiveCfg = Debug|Win32
19 | {481AEBC6-802B-4C8D-8B5B-E3BB3BE6C97B}.Debug|x86.Build.0 = Debug|Win32
20 | {481AEBC6-802B-4C8D-8B5B-E3BB3BE6C97B}.Release|x64.ActiveCfg = Release|x64
21 | {481AEBC6-802B-4C8D-8B5B-E3BB3BE6C97B}.Release|x64.Build.0 = Release|x64
22 | {481AEBC6-802B-4C8D-8B5B-E3BB3BE6C97B}.Release|x86.ActiveCfg = Release|Win32
23 | {481AEBC6-802B-4C8D-8B5B-E3BB3BE6C97B}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {36DCAC0A-9741-40DE-8B53-6D2FEDB554A0}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.exe.recipe:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | C:\Users\Arnit\source\repos\Problem3\Debug\Problem3.exe
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/CL.command.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/CL.command.1.tlog
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/CL.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/CL.read.1.tlog
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/CL.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/CL.write.1.tlog
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/Problem3.lastbuildstate:
--------------------------------------------------------------------------------
1 | PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.34.31933:TargetPlatformVersion=10.0.22000.0:
2 | Debug|Win32|C:\Users\Arnit\Source\Repos\Algoritmer-Datastructure'\|
3 |
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/link-cvtres.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/link-cvtres.read.1.tlog
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/link-cvtres.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/link-cvtres.write.1.tlog
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/link-rc.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/link-rc.read.1.tlog
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/link-rc.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/link-rc.write.1.tlog
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/link.command.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/link.command.1.tlog
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/link.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/link.read.1.tlog
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/link.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/link.write.1.tlog
--------------------------------------------------------------------------------
/Problem3/Debug/Problem3.tlog/unsuccessfulbuild:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/Problem3.tlog/unsuccessfulbuild
--------------------------------------------------------------------------------
/Problem3/Debug/vc143.idb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/vc143.idb
--------------------------------------------------------------------------------
/Problem3/Debug/vc143.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/Debug/vc143.pdb
--------------------------------------------------------------------------------
/Problem3/Problem3.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "TreeWrapper.h"
4 |
5 | using namespace std;
6 |
7 | int main()
8 | {
9 |
10 | TreeWrapper treeWrapper;
11 | string wordString = "heeelllloo";
12 | cout << wordString << endl;
13 |
14 | // converts the string to a char vector
15 | vector vectorString(wordString.begin(), wordString.end());
16 |
17 | vector tempCharVector(vectorString.size());
18 | vector tempWeightVector(vectorString.size());
19 |
20 |
21 |
22 | int tempVectorIteratorValue = 0;
23 |
24 | priority_queue pqueue;
25 |
26 | for (int i = 0; i < vectorString.size(); i++) {
27 | bool isDistinct = true;
28 |
29 | // searchs for duplicates of the current character
30 | for (int j = 0; j < vectorString.size(); j++) {
31 | if (vectorString[i] == tempCharVector[j] && i != j) {
32 | tempWeightVector[j]++;
33 | isDistinct = false;
34 |
35 | }
36 | }
37 | // varifyes that duplicate characters dont get registerd
38 | if (isDistinct) {
39 | tempCharVector[tempVectorIteratorValue] = vectorString[i];
40 | tempWeightVector[tempVectorIteratorValue] = 1;
41 | tempVectorIteratorValue++;
42 | }
43 | }
44 | //creates trees for distinct nodes with the calculated weight
45 | for (int i = 0; i < tempCharVector.size(); i++) {
46 | if (tempWeightVector[i] > 0) {
47 | cout << tempCharVector[i] << ": " << tempWeightVector[i] << endl;
48 | pqueue.push(TreeWrapper(new Tree(tempWeightVector[i], tempCharVector[i])));
49 | }
50 | }
51 |
52 |
53 | // assembles the tree
54 | while (pqueue.size() > 1) {
55 | TreeWrapper treeWrapper1 = pqueue.top();
56 | pqueue.pop();
57 | TreeWrapper treeWrapper2 = pqueue.top();
58 | pqueue.pop();
59 |
60 | int combWaight = treeWrapper1.tree->getWeight() + treeWrapper2.tree->getWeight();
61 | pqueue.push(TreeWrapper(new Tree(combWaight, treeWrapper1.tree, treeWrapper2.tree)));
62 | }
63 |
64 | pqueue.top().tree->treeTraversal(pqueue.top().tree, -1);
65 | pqueue.top().tree->printTree(vectorString);
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/Problem3/Problem3.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 16.0
23 | Win32Proj
24 | {481aebc6-802b-4c8d-8b5b-e3bb3be6c97b}
25 | Problem3
26 | 10.0
27 |
28 |
29 |
30 | Application
31 | true
32 | v143
33 | Unicode
34 |
35 |
36 | Application
37 | false
38 | v143
39 | true
40 | Unicode
41 |
42 |
43 | Application
44 | true
45 | v143
46 | Unicode
47 |
48 |
49 | Application
50 | false
51 | v143
52 | true
53 | Unicode
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | Level3
76 | true
77 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
78 | true
79 |
80 |
81 | Console
82 | true
83 |
84 |
85 |
86 |
87 | Level3
88 | true
89 | true
90 | true
91 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
92 | true
93 |
94 |
95 | Console
96 | true
97 | true
98 | true
99 |
100 |
101 |
102 |
103 | Level3
104 | true
105 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
106 | true
107 |
108 |
109 | Console
110 | true
111 |
112 |
113 |
114 |
115 | Level3
116 | true
117 | true
118 | true
119 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
120 | true
121 |
122 |
123 | Console
124 | true
125 | true
126 | true
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/Problem3/Problem3.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 | Header Files
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Problem3/Problem3.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Problem3/Tree.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "TreeWrapper.h"
4 | #pragma once
5 |
6 | using namespace std;
7 |
8 | // Creates a tree without children
9 | Tree::Tree(int w, char c) {
10 |
11 | weight = w;
12 | this->c = c;
13 | }
14 |
15 | // Creates a tree with children
16 | Tree::Tree(int w, Tree* t1, Tree* t2) {
17 |
18 | weight = w;
19 | c = -2;
20 | left = t1;
21 | right = t2;
22 | };
23 |
24 | Tree::~Tree() {}
25 |
26 | // provides the tree weight
27 | int Tree::getWeight() const{
28 | return weight;
29 | }
30 |
31 | // prints out the values of the provided vector
32 | void Tree::printTree(vector& bitString) const{
33 | // wordstring is the word that gets processed by the priorityqueue
34 | for (int i = 0; i < bitString.size(); i++) {
35 | cout << " " << bitString[i];
36 | }
37 | cout << endl;
38 | }
39 |
40 | // pointer to the left child of the tree
41 | Tree* Tree::getLeft()
42 | {
43 | return left;
44 | }
45 |
46 | // pointer to the right child of the tree
47 | Tree* Tree::getRight()
48 | {
49 | return right;
50 | }
51 |
52 | // checks if it it a leaf-node
53 | bool Tree::isLeaf(Tree* root1, Tree* root2)
54 | {
55 | if (root1 == NULL && root2 == NULL) {
56 | return true;
57 | }
58 | return false;
59 | }
60 |
61 | // function for treaversing the tree in pre orderd fashion
62 | char Tree::treeTraversal(Tree* root, char leftOrRight)
63 | {
64 | char currElementValue = -2;
65 |
66 | if (root == NULL) { // nothing to visit
67 | return NULL;
68 | }
69 |
70 | // regesters the path taken to this node
71 | if (leftOrRight == '0' || leftOrRight == '1') {
72 | currElementValue = leftOrRight;
73 | }
74 | // places the regesterd path on the vector
75 | if (currElementValue != -2) {
76 | bitString.push_back(currElementValue);
77 | }
78 |
79 | // visits left and right child nodes
80 | treeTraversal(root->getLeft(), '0');
81 | treeTraversal(root->getRight(), '1');
82 |
83 | // checks if this is leaf-node
84 | // if it is regesters ':' and current char value and then starts the print process
85 | if (isLeaf(root->left, root->right)) {
86 | if (root->c != -2) {
87 | bitString.push_back(':');
88 | bitString.push_back(root->c);
89 | }
90 | printTree(bitString); // prints the current value of the vector
91 | // removes the added char values from vector
92 | // think of it as erasing your steps when walking back to the previus node
93 | bitString.pop_back();
94 | bitString.pop_back();
95 | }
96 |
97 | // when needed removes an aditional char value from vector
98 | if (!bitString.empty()) {
99 | bitString.pop_back();
100 | }
101 |
102 | return currElementValue;
103 | }
--------------------------------------------------------------------------------
/Problem3/TreeADT.h:
--------------------------------------------------------------------------------
1 | #include
2 | #pragma once
3 |
4 | using namespace std;
5 |
6 | class Tree {
7 |
8 | public:
9 |
10 | Tree(int w, char c); // Creates a tree without children
11 | Tree(int w, Tree* t1, Tree* t2); // Creates a tree with children
12 | ~Tree();
13 | int getWeight() const; // provides the tree weight
14 | void printTree(vector& bitString) const; // prints out the values of the provided vector
15 | Tree* getLeft(); // pointer to the left child of the tree
16 | Tree* getRight(); // pointer to the right child of the tree
17 | char treeTraversal(Tree* root, char leftOrRight); // function for treaversing the tree in pre orderd fashion
18 | bool isLeaf(Tree* root1, Tree* root2); // checks if it it a leaf-node
19 |
20 | private:
21 | Tree* left;
22 | Tree* right;
23 | int weight;
24 | char c;
25 | vector bitString;
26 |
27 | };
28 |
29 |
--------------------------------------------------------------------------------
/Problem3/TreeWrapper.h:
--------------------------------------------------------------------------------
1 | #include "TreeADT.h"
2 | #pragma once
3 |
4 | #ifndef NULL
5 | #define NULL 0
6 | #endif
7 |
8 | struct TreeWrapper {
9 |
10 | TreeWrapper() {
11 | tree = NULL;
12 | }
13 |
14 | TreeWrapper(Tree* t) {
15 | tree = t;
16 | }
17 |
18 | bool operator<(const TreeWrapper& tw) const {
19 | return tree->getWeight() > tw.tree->getWeight();
20 | }
21 |
22 | Tree* tree;
23 |
24 |
25 | };
26 |
--------------------------------------------------------------------------------
/Problem3/x64/Debug/Problem3.exe.recipe:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | C:\Users\Arnit\source\repos\Algoritmer-Datastructure\x64\Debug\Problem3.exe
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Problem3/x64/Debug/Problem3.ilk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/x64/Debug/Problem3.ilk
--------------------------------------------------------------------------------
/Problem3/x64/Debug/Problem3.log:
--------------------------------------------------------------------------------
1 | Problem3.cpp
2 | Tree.cpp
3 | Generating Code...
4 | Problem3.vcxproj -> C:\Users\Arnit\source\repos\Algoritmer-Datastructure\x64\Debug\Problem3.exe
5 |
--------------------------------------------------------------------------------
/Problem3/x64/Debug/Problem3.tlog/CL.command.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/x64/Debug/Problem3.tlog/CL.command.1.tlog
--------------------------------------------------------------------------------
/Problem3/x64/Debug/Problem3.tlog/CL.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/x64/Debug/Problem3.tlog/CL.read.1.tlog
--------------------------------------------------------------------------------
/Problem3/x64/Debug/Problem3.tlog/CL.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/x64/Debug/Problem3.tlog/CL.write.1.tlog
--------------------------------------------------------------------------------
/Problem3/x64/Debug/Problem3.tlog/Problem3.lastbuildstate:
--------------------------------------------------------------------------------
1 | PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.34.31933:TargetPlatformVersion=10.0.22000.0:
2 | Debug|x64|C:\Users\Arnit\source\repos\Algoritmer-Datastructure\|
3 |
--------------------------------------------------------------------------------
/Problem3/x64/Debug/Problem3.tlog/link.command.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/x64/Debug/Problem3.tlog/link.command.1.tlog
--------------------------------------------------------------------------------
/Problem3/x64/Debug/Problem3.tlog/link.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/x64/Debug/Problem3.tlog/link.read.1.tlog
--------------------------------------------------------------------------------
/Problem3/x64/Debug/Problem3.tlog/link.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/x64/Debug/Problem3.tlog/link.write.1.tlog
--------------------------------------------------------------------------------
/Problem3/x64/Debug/tree.obj.enc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/x64/Debug/tree.obj.enc
--------------------------------------------------------------------------------
/Problem3/x64/Debug/vc143.idb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/x64/Debug/vc143.idb
--------------------------------------------------------------------------------
/Problem3/x64/Debug/vc143.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/Problem3/x64/Debug/vc143.pdb
--------------------------------------------------------------------------------
/problem1/insertionSort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | void insertionSort(int *array, int size) {
4 | for (int step = 1; step < size; step++) {
5 | int key = array[step];
6 | int j = step - 1;
7 |
8 | while (key < array[j] && j >= 0) {
9 | array[j + 1] = array[j];
10 | --j;
11 | }
12 | array[j + 1] = key;
13 | }
14 | }
15 |
16 | int main() {
17 | int data[] {9, 5, 1, 4, 3, 15, 24, 33, 45, 76, 99, 230, 225, 312};
18 | int size{std::size(data)};
19 | auto start = std::chrono::high_resolution_clock::now();
20 | insertionSort(data, size);
21 | auto stop = std::chrono::high_resolution_clock::now();
22 | auto duration = std::chrono::duration_cast(stop - start);
23 | std::cout << duration.count() << " nanoseconds" << '\n';
24 |
25 | for(int i{0}; i
2 | #include
3 | int main()
4 | {
5 | std::vector v{4, 7, 5, 3, 10};
6 | int vMax{};
7 | for(int i{0}; ivMax)
10 | vMax=v[i];
11 | }
12 | std::vectorw(++vMax, 0);
13 | for(int i{0}; i
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "GraphADT.h"
7 |
8 | using namespace std;
9 |
10 |
11 | void Graph::isFriendOrAdversary(int relationships[]) {
12 | // Keep track of the number of edges
13 | int edgeCount = 0;
14 |
15 | // Iterate through the array of relationships
16 | for (int i = 0; i < V; i++) {
17 | for (int j = 0; j < V; j++) {
18 | // If there is an edge, increment the edgeCount
19 | if (relationships[i * V + j] == 1) {
20 | edgeCount++;
21 | }
22 | }
23 | }
24 |
25 | // Check if the number of edges is odd or even
26 | if (edgeCount % 2 == 0) {
27 | cout << "This is an adversary" << endl;
28 | }
29 | else{
30 | cout << "This is a friend" << endl;
31 | }
32 |
33 |
34 |
35 |
36 |
37 | }
--------------------------------------------------------------------------------
/problem2/BFS.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "GraphADT.h"
8 |
9 |
10 |
11 | void Graph::BFS(int startNode, int endNode, int relationships[]) {
12 | // visited[i] will be true if there is a
13 | // path from startNode to i
14 | bool* visited = new bool[V];
15 | for (int i = 0; i < V; i++) {
16 | visited[i] = false;
17 | }
18 |
19 | // queue for Breadth First Search
20 | queue q;
21 |
22 | // Mark the current node as visited and enqueue it
23 |
24 | visited[startNode] = true;
25 | q.push(startNode);
26 |
27 | // Create a vector to store the path
28 | vector path;
29 |
30 | // BFS Loop
31 | while (!q.empty()) {
32 | // Dequeueing a vertice from queue
33 | int currNode = q.front();
34 | q.pop();
35 |
36 | // If the current node is the endNode, then the path is found!
37 | if (currNode == endNode) {
38 | //the path should be stored inside a vector
39 | path.push_back(currNode);
40 | int curr = endNode;
41 | while (curr != startNode) {
42 | for (int i = 0; i < V; i++) {
43 | if (relationships[curr * V + i] == 1) {
44 | curr = i;
45 | path.push_back(curr);
46 | break;
47 | }
48 | }
49 | }
50 | // Print the path
51 | cout << "Path from node " << startNode << " to node " << endNode << ": ";
52 | for (int i = path.size() - 1; i >= 0; i--) {
53 | cout << path[i] << " ";
54 | }
55 | cout << endl;
56 | return;
57 | }
58 |
59 |
60 | // First getting all adjacent vertices of the dequeued vertices. Then if a vertice has not been visited then mark it as visisted and enqueue it.
61 | list::iterator i;
62 | for (i = adj[currNode].begin(); i != adj[currNode].end(); ++i) {
63 | if (!visited[*i]) {
64 | visited[*i] = true;
65 | q.push(*i);
66 | // Store the parent of the current node in the relationships array
67 | relationships[*i * V + currNode] = 1;
68 | }
69 | }
70 |
71 | }
72 | // If there is no path between the two vertices, print that there is no path example of this could be from node 3 to 2.
73 | cout << "There is no path from node " << startNode << " to node " << endNode << endl;
74 |
75 | }
76 |
77 |
78 |
--------------------------------------------------------------------------------
/problem2/Graph.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "GraphADT.h"
7 |
8 | Graph::Graph(int V) {
9 | this->V = V;
10 | adj = new list[V];
11 | }
12 | void Graph::addEdge(int v, int w) {
13 | adj[v].push_back(w); // Add w
14 | //to v’s list.
15 | }
16 | bool Graph::isEdge(int v, int w) {
17 | list::iterator i; //list
18 | // iterator used in loops
19 | for (i = adj[v].begin();
20 | i != adj[v].end(); ++i)
21 | if (w == *i) return (true);
22 | return (false);
23 | }
24 | int Graph::getNumNodes() {
25 | return V;
26 | }
27 | void Graph::printGraph() {
28 | for (int v = 0; v < V; ++v) {
29 | cout << "\n Adjacency list of node" << v << "\n head ";
30 | //Iterate over adj[v]
31 | list::iterator i;
32 | for (i = adj[v].begin();
33 | i != adj[v].end(); ++i) {
34 | cout << "-> " << *i;
35 | printf("\n");
36 | }
37 | }
38 | }
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/problem2/GraphADT.h:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | using namespace std;
5 | /* Graph class representing a
6 | directed graph using
7 | adjacency lists representation */
8 | class Graph
9 | {
10 | private:
11 | int V; // No. of vertices
12 | list* adj; // Pointer to an array containing adjacency lists
13 |
14 | /* Pointer to an
15 | array containing
16 | adjacency lists */
17 | public:
18 | Graph(int V); // Constructor
19 | /* Add an edge to graph */
20 | void addEdge(int v, int w);
21 | // check if there is an edge in graph
22 | bool isEdge(int v, int w);
23 | // get number of nodes
24 | int getNumNodes();
25 | /* print the adjacency list
26 | representation of graph*/
27 | void printGraph();
28 |
29 | // prints BFS traversal
30 | void BFS(int startNode, int endNode, int relationships[]);
31 | // Is it friend or not?
32 | void isFriendOrAdversary(int relationships[]);
33 |
34 |
35 |
36 | };
--------------------------------------------------------------------------------
/problem2/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "GraphADT.h"
7 |
8 |
9 | using namespace std;
10 |
11 |
12 | int main() {
13 | // Create a graph
14 | Graph g(4);
15 | g.addEdge(0, 1);
16 | g.addEdge(1, 2);
17 | g.addEdge(2, 1);
18 | g.addEdge(1, 3);
19 | g.addEdge(2, 3);
20 | // print the graph
21 | // Create an array of relationships
22 | int relationships[16] = {};
23 | // In BFS function, we will store the path from startNode to endNode in this vector
24 | g.BFS(2, 3, relationships);
25 |
26 | // Check if the given node is a friend or adversary, put the parameters: startNode and relationships
27 | g.isFriendOrAdversary(relationships);
28 | }
--------------------------------------------------------------------------------
/x64/Debug/Problem3.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zupils/Algoritmer-Datastructure/595c156591aae00ca9751dd2d1d8f14ecddcb8e6/x64/Debug/Problem3.pdb
--------------------------------------------------------------------------------