-
Notifications
You must be signed in to change notification settings - Fork 0
/
close.cpp
45 lines (39 loc) · 1.06 KB
/
close.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "close.h"
#include "utils.h"
Close::Close() {
}
void Close::add(Node* node) {
nodes.push_back(node);
}
//将node按照f从小到大插入
void Close::addSort(Node* node) {
for (int i = 0, len = nodes.size(); i < len; i++) {
if (node->f < nodes[i]->f) {
nodes.insert(nodes.begin() + i, node);
return;
}
}
nodes.push_back(node);
}
bool Close::find(Node* node) {
for (int i = 0, len = nodes.size(); i < len; i++) {
if (same(node->state, nodes[i]->state, node->m, node->n)) {
if (node->depth < nodes[i]->depth) {
nodes[i]->parent = node->parent;
}
return true;
}
}
return false;
}
void Close::findReplaceAdd(Node* node) {
for (int i = 0, len = nodes.size(); i < len; i++) {
if (same(node->state, nodes[i]->state,node->m,node->n)) {
if (node->f < nodes[i]->f) {
nodes[i] = node;
return;
}
}
}
addSort(node);
}