修复好bug了
This commit is contained in:
@@ -3,6 +3,4 @@ project(homework5)
|
|||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
add_executable(test1 test1.cpp
|
add_executable(test2 test2.cpp)
|
||||||
MatrixGraph.h
|
|
||||||
GraphExceptions/InsertExistedConnectException.h)
|
|
||||||
|
|||||||
+2
-20
@@ -37,18 +37,10 @@ private:
|
|||||||
bool isWeighted; //定义是否有权
|
bool isWeighted; //定义是否有权
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListGraph() {
|
ListGraph(bool flag=false,bool isWeighted=false) {
|
||||||
nodes.clear();
|
nodes.clear();
|
||||||
flag = false;
|
flag = false;
|
||||||
isWeighted = false;
|
isWeighted = false;
|
||||||
}
|
|
||||||
ListGraph(bool flag) {
|
|
||||||
nodes.clear();
|
|
||||||
this->flag = flag;
|
|
||||||
isWeighted = false;
|
|
||||||
}
|
|
||||||
ListGraph(bool flag,bool isWeighted) {
|
|
||||||
nodes.clear();
|
|
||||||
this->flag = flag;
|
this->flag = flag;
|
||||||
this->isWeighted = isWeighted;
|
this->isWeighted = isWeighted;
|
||||||
}
|
}
|
||||||
@@ -70,7 +62,7 @@ public:
|
|||||||
}
|
}
|
||||||
node *current = nodes.at(id1);
|
node *current = nodes.at(id1);
|
||||||
//跳过id节点和值节点
|
//跳过id节点和值节点
|
||||||
for(int i=0;i<2;i++) {
|
for(int i=0;i<1;i++) {
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
while(current->next!=NULL) {
|
while(current->next!=NULL) {
|
||||||
@@ -89,17 +81,7 @@ public:
|
|||||||
|
|
||||||
if (!flag) {
|
if (!flag) {
|
||||||
node *current2 = nodes.at(id2);
|
node *current2 = nodes.at(id2);
|
||||||
//跳过id节点和值节点
|
|
||||||
for(int i=0;i<2;i++) {
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
while(current2->next!=NULL) {
|
while(current2->next!=NULL) {
|
||||||
if((current2->next->data==id2)) {
|
|
||||||
if (current2->next->weight==weight) {
|
|
||||||
throw InsertExistedConnectException("禁止插入已存在的连接",0x003);
|
|
||||||
}
|
|
||||||
current2->next->weight=weight;
|
|
||||||
}
|
|
||||||
current2 = current2->next;
|
current2 = current2->next;
|
||||||
}
|
}
|
||||||
current2->next=new node();
|
current2->next=new node();
|
||||||
|
|||||||
@@ -25,11 +25,5 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
ListGraph<int> list_graph;
|
|
||||||
list_graph.insert(1);
|
|
||||||
list_graph.insert(2);
|
|
||||||
list_graph.connect(0,1);
|
|
||||||
list_graph.connect(1,0);
|
|
||||||
cout << list_graph.to_string() << endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user