-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTopo_DeleteRouter.cpp
More file actions
40 lines (32 loc) · 930 Bytes
/
Topo_DeleteRouter.cpp
File metadata and controls
40 lines (32 loc) · 930 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
35
36
37
38
39
40
#include"Topo.h"
#include<cstdlib>
extern bool IPcmp(int *ip1,int *ip2);
bool Topo::DeleteRouter(int *ip){
Table* ptr = head;
Table* last = nullptr;
Table* temp = head;
Line*lp = nullptr,*lpp=nullptr;
for(ptr = head;ptr != nullptr;ptr = ptr->next)
{
if(IPcmp(ip,ptr->data->RouterIP))//找到指向这个路由器的指针
break;
if(last == nullptr)
last = head; //找到指向这个路由器前一个节点用于删除
else last = ptr;
}
if(ptr != nullptr)
lp = ptr->data->LineHead; //把路由器摘出来,再进行其他删除
else return false;
while(lp!=nullptr) //删除边
{
lpp=lp->next;
DeleteLine(lp->IP1,lp->IP2);
lp=lpp;
}
if(last == nullptr) //从链表删除路由器
head = head->next;
else last->next = ptr->next;
delete ptr;
reRTable();
return true;
}