DSA-Assignments

Log | Files | Refs | README

commit b4e45ac8a20f2905e4948e33b02ad259d56f6b7a
parent 66c90810805c4579c7e829944244b7604a5535b4
Author: Victor Adamson <a20vicad@student.his.se>
Date:   Wed, 29 Nov 2023 15:38:03 +0100

Added graph ADT

Diffstat:
MProblem2/Problem2.cpp | 74+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 67 insertions(+), 7 deletions(-)

diff --git a/Problem2/Problem2.cpp b/Problem2/Problem2.cpp @@ -1,15 +1,75 @@ - +// Problem 2: Social Network +// Description: +// Course: IT405G - Datastructures and Algorithms +// Authors: William Lindholm, Lili Tran, Victor Adamson +// Date: 29-11-2023 +// #include <iostream> #include <queue> +#include <vector> using namespace std; -int main() -{ - queue<int> network; +class Graph { +private: + int V; + vector<int>* adj; +public: + Graph(int V); + void addEdge(int v, int w); + bool isEdge(int v, int w); + int getNumNodes(); + void printGraph(); +}; + +Graph::Graph(int V) { + this->V = V; + adj = new vector <int>[V]; +} + +void Graph::addEdge(int v, int w) { + adj[v].push_back(w); +} + +bool Graph::isEdge(int v, int w) { + vector<int>::iterator i; + for (i = adj[v].begin(); i != adj[v].end(); i++) { + if (w == *i) { + return(true); + } + return(false); + } +} + +int Graph::getNumNodes() { + return V; +} - while (!network.empty()) { - cout << ' ' << network.front(); - network.pop(); +void Graph::printGraph() { + for (int v = 0; v < V; ++v) { + cout << "\n Adjacency list of node " << v << "\n head "; + vector<int>::iterator i; + for (i = adj[v].begin(); + i != adj[v].end(); ++i) { + cout << "-> " << *i << " "; + } } +} + +int main(){ + queue<int>; + Graph network(4); + vector<bool> visited[4]; + network.addEdge(0, 1); + network.addEdge(1, 2); + network.addEdge(1, 3); + network.addEdge(3, 1); + network.addEdge(3, 2); + + network.printGraph(); + +} + +bool isAdversary(Graph network) { + return true; } \ No newline at end of file