Skip to content

Commit

Permalink
Server response: graph
Browse files Browse the repository at this point in the history
  • Loading branch information
brunolnetto committed Jan 9, 2022
1 parent d7f8ac9 commit 435fff3
Showing 1 changed file with 9 additions and 39 deletions.
48 changes: 9 additions & 39 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import express from 'express'
import Graph from './data-structures/graph/Graph.js'
import GraphVertex from './data-structures/graph/GraphVertex.js'
import GraphEdge from './data-structures/graph/GraphEdge.js'
import depthFirstSearch from './algorithms/depth-first-search/depthFirstSearch.js'

const app = express();

Expand All @@ -25,6 +26,7 @@ app.get('/', (req, res) => {
// Create a sample graph
// const graph = req.blueprint.nodes;

// A directed graph
let graph_ = new Graph(true);

// Nodes
Expand All @@ -41,11 +43,14 @@ app.get('/', (req, res) => {
let CA = new GraphEdge(C, A);
let CB = new GraphEdge(C, B);

graph_.addVertex(A);
graph_.addVertex(B);
graph_.addVertex(C);
graph_.addVertex(D);
// Add vertices
graph_
.addVertex(A)
.addVertex(B)
.addVertex(C)
.addVertex(D);

// Add edges
graph_
.addEdge(AB)
.addEdge(AC)
Expand All @@ -54,42 +59,7 @@ app.get('/', (req, res) => {
.addEdge(CA)
.addEdge(CB);

console.log(graph_.getAllEdges());
console.log(graph_.getAllVertices());
res.send(graph_.toString());

/*
// arbitrary source
let from_ = 1;
// arbitrary destination
let to = 3;
let all_paths = s.allPaths(from_, to);
let all_vicinity = s.allVicinity();
let loose_nodes = s.looseNodes();
console.log('Paths from '+from_+' to '+to+' :');
console.log(all_paths);
console.log('Reachibility: ');
console.log(all_vicinity);
console.log('Loose nodes: ');
console.log(loose_nodes);
let text_ = "Original code from the URL : <a href=https://www.geeksforgeeks.org/find-paths-given-source-destination//> Graph paths original post </a> " + "<br>";
if(all_paths.length==0){
text_ = text_ + 'There is no path available from ' + from_ + ' to ' + to + '!';
} else {
text_ = text_ + "Following are all different paths from " + from_ + " to " + to + "<br>";
for (let i=0; i<all_paths.length; i++) {
text_ = text_ + all_paths[i] + "<br>";
}
}
*/
});
// [END app]

0 comments on commit 435fff3

Please sign in to comment.