读取一张图
使用 nodejs 本身自带的文件读取模块 read-line
代码实现
const fs = require('fs');
const readline = require('readline');
// const DenseGraph = require('./dense-graph');
const SparseGraph = require('./sparse-graph');
const DFSComponent = require('./dfs');
const Path = require('./find-a-path');
const BFCComponent = require('./bfs');
const rl = readline.createInterface({
input: fs.createReadStream('/Users/da.liu/person/graph/testG1.txt'),
output: process.stdout,
terminal: false
});
const length = 13;
const sg = new SparseGraph(length, false);
let index = 0;
rl.on('line', (line) => {
if (index === length - 1) {
// const dfsc = new DFSComponent(sg);
// console.log(dfsc.count());
// const path = new Path(sg, 0);
// path.showPath(3);
const path = new BFCComponent(sg, 0);
path.showPath(3);
}
if (index !== 0) {
const [v, w] = line.split(/\s/);
// dg.addEdge(v, w);
sg.addEdge(v, w);
}
index++;
// console.log(dg.g);
});
FEATURED TAGS
前端开发
H5
JavaScript
设计模式
browser
jQuery
源码分析
生活
leetcode
Array
Stack
Queue
Linked List
剑指offer
Binary Search Tree
Binary Tree
Breadth-First Search
Depth-First Search
String
Set
Binary Search
Sliding Window
Backtracking
Dynamic Programming
Two Pointers
Union Find
Sort
Bit Operation
Recursion
Map
Graph
Search
Hash
LinkedList
复盘
QuickSort
Trie
Design
MinHeap
Traverse
Min Heap
Node.js
BackEnd
SQL
MySQL
Design Patterns
Network
计算机网络
Python
SVG