1 Star 0 Fork 68

zb872676223/图与网络优化_Qt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
basematrix.cpp 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
ZzqiZQute 提交于 2018-06-25 21:36 . 20186252136
#include "basematrix.h"
#include "basevector.h"
BaseMatrix::BaseMatrix()
{
vectors=new QList<BaseVector*>();
}
QList<BaseVector *> *BaseMatrix::getVectors() const
{
return vectors;
}
void BaseMatrix::addVector(BaseVector *vector)
{
vectors->push_back(vector);
}
void BaseMatrix::removeVector(int v1,int v2)
{
for(int i=0;i<vectors->count();i++){
if((v1==vectors->at(i)->getV1()&&v2==vectors->at(i)->getV2())
||(v2==vectors->at(i)->getV1()&&v1==vectors->at(i)->getV2())){
vectors->removeAt(i);
break;
}
}
}
bool BaseMatrix::isBaseVector(int v1, int v2)
{
for(int i=0;i<vectors->count();i++){
if((v1==vectors->at(i)->getV1()&&v2==vectors->at(i)->getV2())
||(v2==vectors->at(i)->getV1()&&v1==vectors->at(i)->getV2())){
return true;
}
}
return false;
}
BaseVector *BaseMatrix::getBaseVector(int v1, int v2)
{
for(int i=0;i<vectors->count();i++){
if((v1==vectors->at(i)->getV1()&&v2==vectors->at(i)->getV2())
||(v2==vectors->at(i)->getV1()&&v1==vectors->at(i)->getV2())){
return vectors->at(i);
}
}
return NULL;
}
void BaseMatrix::clearVectors()
{
vectors->clear();
}
int BaseMatrix::getCount() const
{
return vectors->count();
}
QList<int> BaseMatrix::getCircuit(int v1, int v2)
{
QList<int> list;
list.push_back(v1);
for(int i=0;i<vectors->count();i++){
vectors->at(i)->setSelected(false);
}
int p=0;
while(p!=v2){
int q=list.at(list.count()-1);
p=0;
for(int i=0;i<vectors->count();i++){
if(!vectors->at(i)->getSelected()){
if(q==vectors->at(i)->getV1()){
p=vectors->at(i)->getV2();
}else if(q==vectors->at(i)->getV2())
p=vectors->at(i)->getV1();
if(p!=0){
vectors->at(i)->setSelected(true);
list.append(p);
break;
}
}
}
if(p==0){
list.removeAt(list.count()-1);
}
}
return list;
}
int BaseMatrix::getDegree(int v)
{
int ret=0;
for(int i=0;i<vectors->count();i++){
if(v==vectors->at(i)->getV1()||v==vectors->at(i)->getV2())
ret++;
}
return ret;
}
bool BaseMatrix::isDegreeOne(int v){
return getDegree(v)==1;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/zb872676223/graph_and_network_optimization_qt.git
[email protected]:zb872676223/graph_and_network_optimization_qt.git
zb872676223
graph_and_network_optimization_qt
图与网络优化_Qt
master

搜索帮助