-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTopo_Insert.cpp
More file actions
34 lines (34 loc) · 970 Bytes
/
Topo_Insert.cpp
File metadata and controls
34 lines (34 loc) · 970 Bytes
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
#include"Topo.h"
#include"Table.h"
extern bool IPcmp(int *ip1,int *ip2);
bool Topo::Insert(int *ip1,int *ip2,int weight,bool Double){
Table* ptr = head;
for(ptr = head;ptr != nullptr;ptr = ptr->next){ //找到路由器
if(IPcmp(ip1,ptr->data->RouterIP)){
break;
}
}
if(ptr != nullptr){
ptr->data->BuildLine(ip2,weight); //创建边
}
else if(ptr == nullptr){ //如果不存在路由器,则创建
head = new Table(ip1,head);
head->data->BuildLine(ip2,weight);
ptr=head;
reRTable();
}
if(Double){
for(ptr = head;ptr != nullptr;ptr = ptr->next){
if(IPcmp(ip2,ptr->data->RouterIP)){
break;
}
}
if(ptr != nullptr){
ptr->data->BuildLine(ip1,weight);
}
else if(ptr == nullptr){
head = new Table(ip2,head);
head->data->BuildLine(ip1,weight);
}
}
}