資源簡介
無向圖的深度優先森林(孩子兄弟鏈表表示)

代碼片段和文件信息
#include“ALGraph.h“
#include?
#include?
#include
#include?
#include
using?namespace?std;
ALGraph::ALGraph()
{
vexNum?=?0;
edgeNum?=?0;
alGVersion?=?0;?//?默認無向圖
}
ALGraph::~ALGraph()
{
this->empty();
}
void?ALGraph::setVexNum(int?vn)
{
vexNum?=?vn;
}
int?ALGraph::getVexNum()
{
return?vexNum;
}
void?ALGraph::setEdgeNum(int?en)
{
edgeNum?=?en;
}
int?ALGraph::getEdgeNum()
{
return?edgeNum;
}
void?ALGraph::setALGVersion(int?version)
{
alGVersion?=?version;
}
int?ALGraph::getALGVersion()
{
return?alGVersion;
}
void?ALGraph::deleteEdge(int?f?int?t)
{
//?要考慮?1?邊不一定存在?2?刪除的邊的?to?節點在鏈表的?firstArc
VNode?vex?=?this->vetices[f?-?1];
ArcNode?*arcNode?=?vex.getFirstArc();
ArcNode?*BeforeArcNode?=?new?ArcNode();
int?isfirst?=?1;
while?(arcNode?&&?!(arcNode->getAdjvex()?==?t))
{
isfirst?=?0;
BeforeArcNode?=?arcNode;
arcNode?=?BeforeArcNode->getNextarc();
}
if?(arcNode)?//?邊是存在的
{
vetices[t?-?1].setIn(vetices[t?-?1].getIn()?-?1);
vetices[f?-?1].setOut(vetices[f?-?1].getOut()?-?1);
if?(isfirst)?//?firstArc
{
vex.setFirstArc(arcNode->getNextarc());
}
else
{
BeforeArcNode->setNextarc(arcNode->getNextarc());
}
this->setEdgeNum(this->edgeNum?-?1);
delete?arcNode;
if?(!this->alGVersion)?//?無向圖
{
vex?=?this->vetices[t?-?1];
arcNode?=?vex.getFirstArc();
BeforeArcNode?=?new?ArcNode();
isfirst?=?1;
while?(arcNode?&&?!(arcNode->getAdjvex()?==?f))
{
isfirst?=?0;
BeforeArcNode?=?arcNode;
arcNode?=?BeforeArcNode->getNextarc();
}
if?(arcNode)?//?邊是存在的
{
vetices[f?-?1].setIn(vetices[f?-?1].getIn()?-?1);
vetices[t?-?1].setOut(vetices[t?-?1].getOut()?-?1);
if?(isfirst)?//?firstArc
{
vex.setFirstArc(arcNode->getNextarc());
}
else
{
BeforeArcNode->setNextarc(arcNode->getNextarc());
}
delete?arcNode;
}
}
}
}
void?ALGraph::deleteVex(int?delVex)
{
VNode?*vex?=?&(this->vetices[delVex?-?1]);
ArcNode?*arcNode?=?vex->getFirstArc();
ArcNode?*BeforeArcNode?=?new?ArcNode();
while?(arcNode)
{
//?從鏈表的第一個?arcNode?開始刪
int?adjVex?=?arcNode->getAdjvex();
vetices[adjVex?-?1].setIn(vetices[adjVex?-?1].getIn()?-?1);
BeforeArcNode?=?arcNode;
vex->setFirstArc(BeforeArcNode->getNextarc());
arcNode?=?BeforeArcNode->getNextarc();
delete?BeforeArcNode;
if?(!this->alGVersion)?//?無向圖
{
this->deleteEdge(adjVex?delVex);
}
}
vex->setVNum(0);?//在數組中?刪除節點
vex->setIn(-1)?;
vex->setOut(-1)?;
this->vexNum--;
}
void?ALGraph::addEdge(int?f?int?t?int?w)
{
//?找到起點的鏈接鏈表?
ArcNode?*newArcNode?=?new?ArcNode(t?w);
VNode?*vnodeF?=?new?VNode()??*vnodeT?=?new?VNode();
vnodeF?=?&(vetices[f?-?1]);
vnodeT?=?&(vetices[t?-?1]);
vnodeF->setOut(vnodeF->getOut()?+?1);
vnodeT->setIn(vnodeT->getIn()?+?1)?;
newArcNode->setNextarc(vnodeF->getFirstArc());
vno
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????15779??2016-09-05?14:41??cstree\ALGraph.cpp
?????文件???????1416??2016-09-05?13:58??cstree\ALGraph.h
?????文件?????????82??2016-09-05?20:46??cstree\ALGraph.txt
?????文件????????516??2016-08-14?15:36??cstree\arcNode.cpp
?????文件????????469??2016-09-01?16:24??cstree\ArcNode.h
?????文件????????585??2016-09-05?14:42??cstree\CSNode.h
?????文件??????????2??2016-09-05?14:45??cstree\CSTree.cpp
?????文件????????413??2016-09-05?14:48??cstree\CSTree.h
?????文件???????8290??2016-09-05?15:00??cstree\cstree.vcxproj
?????文件???????2407??2016-09-05?15:00??cstree\cstree.vcxproj.filters
?????文件????????476??2016-09-05?20:41??cstree\cstree1.cpp
?????文件?????555410??2016-09-05?20:46??cstree\Debug\ALGraph.obj
?????文件??????31598??2016-09-05?14:38??cstree\Debug\arcNode.obj
?????文件????????147??2016-09-05?20:46??cstree\Debug\cstree.log
?????文件???????2295??2016-09-05?14:46??cstree\Debug\CSTree.obj
?????文件???????4266??2016-09-05?20:46??cstree\Debug\cstree.tlog\CL.command.1.tlog
?????文件??????52704??2016-09-05?20:46??cstree\Debug\cstree.tlog\CL.read.1.tlog
?????文件???????7372??2016-09-05?20:46??cstree\Debug\cstree.tlog\CL.write.1.tlog
?????文件????????205??2016-09-05?20:46??cstree\Debug\cstree.tlog\cstree.lastbuildstate
?????文件???????1960??2016-09-05?20:46??cstree\Debug\cstree.tlog\li
?????文件???????3824??2016-09-05?20:46??cstree\Debug\cstree.tlog\li
?????文件???????1104??2016-09-05?20:46??cstree\Debug\cstree.tlog\li
?????文件?????183234??2016-09-05?20:46??cstree\Debug\cstree1.obj
?????文件??????30991??2016-09-05?20:46??cstree\Debug\main.obj
?????文件?????502784??2016-09-05?20:46??cstree\Debug\vc140.idb
?????文件?????520192??2016-09-05?20:46??cstree\Debug\vc140.pdb
?????文件??????36751??2016-09-05?14:38??cstree\Debug\VNode.obj
?????文件????????657??2016-09-05?14:38??cstree\main.cpp
?????文件????????966??2016-08-18?12:45??cstree\VNode.cpp
?????文件????????701??2016-09-01?16:24??cstree\VNode.h
............此處省略6個文件信息
- 上一篇:51單片機熱敏電阻測溫查表程序
- 下一篇:sopc開發的
評論
共有 條評論