Skip to content

Commit

Permalink
[Graph] Add playground
Browse files Browse the repository at this point in the history
  • Loading branch information
deunlee committed May 30, 2020
1 parent e005ad0 commit 474e11b
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 58 deletions.
3 changes: 2 additions & 1 deletion Graph/Graph.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<DisableSpecificWarnings>4819;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -155,7 +156,7 @@
<ClCompile Include="AdjacencyList.cpp" />
<ClCompile Include="AdjacencyMatrix.cpp" />
<ClCompile Include="Graph.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="Playground.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
2 changes: 1 addition & 1 deletion Graph/Graph.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
<ClCompile Include="Graph.cpp" />
<ClCompile Include="AdjacencyMatrix.cpp" />
<ClCompile Include="AdjacencyList.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="Playground.cpp" />
</ItemGroup>
</Project>
56 changes: 0 additions & 56 deletions Graph/Main.cpp

This file was deleted.

114 changes: 114 additions & 0 deletions Graph/Playground.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include <iostream>
using namespace std;

#include "AdjacencyMatrix.h"
#include "AdjacencyList.h"
#include "Graph.h"
using namespace Deun;

void adjacencyMatrixPG() {
AdjacencyMatrix adjMatrix(5);
int menu, value1, value2;

cout << boolalpha;
cout << "< AdjacencyMatrix Playground >" << endl << endl;

while (1) {
adjMatrix.print();
cout << ">>> insertVertex=1, insertEdge=2, hasVertex=3, hasEdge=4 : ";
cin >> menu;

switch (menu) {
case 1:
try {
cout << ">>> insertVertex(): " << adjMatrix.insertVertex();
}
catch (AdjacencyMatrixError err) {
cout << ">>> insertVertex(): Error Code " << (int)err;
}
break;

case 2:
cout << ">>> from and to : ";
cin >> value1 >> value2;
cout << ">>> insertEdge(" << value1 << ", " << value2 << "): ";
cout << adjMatrix.insertEdge(value1, value2);
break;

case 3:
cout << ">>> index : ";
cin >> value1;
cout << ">>> hasVertex(" << value1 << "): " << adjMatrix.hasVertex(value1);
break;

case 4:
cout << ">>> from and to : ";
cin >> value1 >> value2;
cout << ">>> hasEdge(" << value1 << ", " << value2 << "): ";
cout << adjMatrix.hasEdge(value1, value2);
break;

default:
cout << ">>> unknown command";
}

cout << endl << "--------------------------------------------------" << endl;
}
}

void adjacencyListPG() {
AdjacencyList adjList(5);
int menu, value1, value2;

cout << boolalpha;
cout << "< AdjacencyList Playground >" << endl << endl;

while (1) {
adjList.print();
cout << ">>> insertVertex=1, insertEdge=2, hasVertex=3, hasEdge=4 : ";
cin >> menu;

switch (menu) {
case 1:
try {
cout << ">>> insertVertex(): " << adjList.insertVertex();
}
catch (AdjacencyListError err) {
cout << ">>> insertVertex(): Error Code " << (int)err;
}
break;

case 2:
cout << ">>> from and to : ";
cin >> value1 >> value2;
cout << ">>> insertEdge(" << value1 << ", " << value2 << "): ";
cout << adjList.insertEdge(value1, value2);
break;

case 3:
cout << ">>> index : ";
cin >> value1;
cout << ">>> hasVertex(" << value1 << "): " << adjList.hasVertex(value1);
break;

case 4:
cout << ">>> from and to : ";
cin >> value1 >> value2;
cout << ">>> hasEdge(" << value1 << ", " << value2 << "): ";
cout << adjList.hasEdge(value1, value2);
break;

default:
cout << ">>> unknown command";
}

cout << endl << "--------------------------------------------------" << endl;
}
}

int main() {
//adjacencyMatrixPG();
adjacencyListPG();

return 0;
}

0 comments on commit 474e11b

Please sign in to comment.