SetName + replaceDataFromFile

This commit is contained in:
Морозов Андрей 2021-11-05 15:25:16 +04:00
parent e4d8d6133c
commit 26d610b302
1 changed files with 45 additions and 6 deletions

View File

@ -174,6 +174,8 @@ class Graphs {
_fixAfterDel(inn);
return null;
}
void flushData() => _dots = <Dot>[];
//*********Delete*********
//******Helper*******
@ -242,6 +244,49 @@ class Graphs {
}
//******Helper*******
//*****Setters*******
void setName(String name) => _name = name;
String? replaceDataFromFile(String path) {
Separators sep = Separators();
File file = File(path);
List<String> lines = file.readAsLinesSync();
_name = lines.removeAt(0);
_oriented = lines.removeAt(0) == sep.isOriented.trim();
_useLength = lines.removeAt(0) == sep.hasLength.trim();
_dots = <Dot>[];
for (var l in lines) {
l = l.trimRight();
if (l != sep.end) {
var spl = l.split(sep.space);
List<int> dot = <int>[];
List<int> len = <int>[];
String name = spl.removeAt(0);
name = name.substring(0, name.length - 1);
for (var splitted in spl) {
if (splitted != "") {
var dt = splitted.split(sep.dotToLength);
if (dt.length == 2) {
dot.add(int.parse(dt[0]));
if (_useLength) {
len.add(int.parse(dt[1]));
} else {
len.add(0);
}
} else if (dt.length == 1) {
dot.add(int.parse(splitted));
len.add(0);
}
}
}
_dots.add(Dot.fromTwoLists(name, dot, len));
}
}
_syncNum();
_syncNameTable();
if (!_oriented) _fullFix();
}
//*****Setters*******
//*****Getters*******
bool getDoubleSided() => _oriented;
bool getUseLength() => _useLength;
@ -401,12 +446,6 @@ class Graphs {
_syncNameTable();
}
//***********Cleaning***********
void flushData() {
_dots = <Dot>[];
}
//***********Cleaning***********
//************Алгоритмы************
bool bfsHasPath(int startDot, int goalDot) {
// обход в ширину