This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/ex11/ex11.cpp

73 lines
1.8 KiB
C++
Raw Normal View History

2021-12-09 14:58:46 +00:00
#include "graph.hpp"
2021-12-09 15:22:41 +00:00
#include <iostream>
2021-12-09 15:04:48 +00:00
#include <stdio.h>
2021-12-09 15:22:41 +00:00
2021-12-09 14:58:46 +00:00
int main()
{
2021-12-10 01:20:41 +00:00
// typedef struct data
// {
// int id;
// std::string name;
// }data;
2021-12-09 15:22:41 +00:00
graphVertex<int, std::string> gv;
int op, id1, id2, w;
std::string name;
while (1)
{
2021-12-10 08:51:43 +00:00
printf("选择操作:1添加/覆盖节点2添加边3删除节点4删除边5显示图\n");
2021-12-09 15:22:41 +00:00
scanf("%d", &op);
switch (op)
{
case 1:
printf("分别输入序号 节点名:");
std::cin >> id1 >> name;
2021-12-10 08:51:43 +00:00
printf("插入到ID位%d的位置\n", gv.insect(id1, name));
2021-12-09 15:22:41 +00:00
break;
case 2:
printf("分别输入起始节点序号 到达节点序号 边权重:");
std::cin >> id1 >> id2 >> w;
2021-12-10 09:08:32 +00:00
if(id1==id2)
printf("失败\n");
2021-12-10 08:51:43 +00:00
switch (gv.link(id1, id2, w))
{
case 0:
printf("成功\n");
break;
case -1:
printf("顶点不存在\n");
break;
case -2:
printf("边已经存在\n");
break;
}
2021-12-09 15:22:41 +00:00
break;
case 3:
printf("输入节点序号:");
std::cin >> id1;
2021-12-10 08:51:43 +00:00
gv.remove(id1);
2021-12-09 15:22:41 +00:00
break;
case 4:
printf("分别输入起始节点序号 到达节点序号:");
std::cin >> id1 >> id2;
2021-12-10 08:51:43 +00:00
switch (gv.unlink(id1, id2))
{
case 0:
printf("成功\n");
break;
case -1:
printf("顶点不存在\n");
break;
case -2:
printf("边不存在\n");
break;
}
2021-12-09 15:22:41 +00:00
break;
2021-12-10 01:20:41 +00:00
case 5:
gv.display();
2021-12-09 15:22:41 +00:00
default:
break;
}
}
2021-12-09 14:58:46 +00:00
return 0;
}