-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
102 lines (95 loc) · 2.2 KB
/
main.cpp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <vector>
#include "Graph.h"
using namespace std;
int main(){
Graph firstGraph;
int a,b,input;
do
{
std::cout<<"Enter the number to peform the following operations:"<<std::endl;
std::cout<<"1.Add node to the graph.\n2.Add undirected edge\n3.Check if node exists.\n4.Check if edge exists.\n5.Delete node\n6.Delete undirected edge\n7.Print the node list.\n8.Print the edge list.\n9.Find the friends and friends of friends of a node. (Breadth First Search)\n"
"Press 0 to exit\n"<<std::flush;
std::cin>>input;
switch(input)
{
case 1:
{
std::cout<<"Enter the node you want to add"<<std::endl;
std::cin>>a;
firstGraph.addNode(a);
break;
}
case 2:
{
std::cout<<"Enter the nodes which you want to connect( as friends)"<<std::endl;
std::cin>>a;
std::cin>>b;
firstGraph.addUnEdge(a,b);
break;
}
case 3:
{
std::cout<<"Enter the node to check"<<std::endl;
std::cin>>a;
if(firstGraph.checkNode(a))
{
std::cout<<"The node "<<a<<"exists"<<std::endl;
}
else
{
std::cout<<"The node doesnot exist"<<std::endl;
}
break;
}
case 4:
{
std::cout<<"Enter the nodes to check edge"<<std::endl;
std::cin>>a>>b;
if(firstGraph.checkEdge(a,b))
{
std::cout<<"The edge ("<<a<<","<<b<<") exists"<<std::endl;
}
else
std::cout<<"The edge doesnot exist"<<std::endl;
break;
}
case 5:
{
std::cout<<"Enter the node to delete"<<std::endl;
std::cin>>a;
firstGraph.deleteNode(a);
break;
}
case 6:
{
std::cout<<"Enter the nodes of edge you want to remove"<<std::endl;
std::cin>>a>>b;
firstGraph.deleteUnEdge(a,b);
break;
}
case 7:
{
firstGraph.printNodeList();
break;
}
case 8:
{
firstGraph.printEdgeList();
break;
}
case 9:
{
std::cout<<"Enter the node whose friends you want to find"<<std::endl;
std::cin>>a;
firstGraph.breadthfirstTraversal(a);
break;
}
case 0:
break;
default:
std::cout<<"Please enter the valid number"<<std::endl;
}
}while(input!=0);
return 0;
}