Ex 9 Grpahs
Ex 9 Grpahs
NO:8 GRAPHS
10.02.21
AIM:
PROGRAM:
#include <iostream>
#include <list>
#include <stack>
class Graph {
int V;
list<int>* adj;
public:
Graph(int V);
void topologicalSort();
};
Graph::Graph(int V)
this->V = V;
adj[v].push_back(w);
T.PRABAVATHI(MTECH)
20MA32
}
visited[v] = true;
list<int>::iterator i;
if (!visited[*i])
Stack.push(v);
void Graph::topologicalSort()
stack<int> Stack;
visited[i] = false;
if (visited[i] == false)
Stack.pop();
int main()
T.PRABAVATHI(MTECH)
20MA32
Graph g(6);
g.addEdge(5, 2);
g.addEdge(5, 0);
g.addEdge(4, 0);
g.addEdge(4, 1);
g.addEdge(2, 3);
g.addEdge(3, 1);
g.topologicalSort();
return 0;
#include <limits.h>
#include <stdio.h>
#define V 9
T.PRABAVATHI(MTECH)
20MA32
for (int v = 0; v < V; v++)
return min_index;
int dist[V]; // The output array. dist[i] will hold the shortest
T.PRABAVATHI(MTECH)
20MA32
for (int i = 0; i < V; i++)
dist[src] = 0;
// Pick the minimum distance vertex from the set of vertices not
sptSet[u] = true;
T.PRABAVATHI(MTECH)
20MA32
printSolution(dist);
int main()
dijkstra(graph, 0);
return 0;
T.PRABAVATHI(MTECH)
20MA32