Chinaunix首页 | 论坛 | 博客
  • 博客访问: 188873
  • 博文数量: 45
  • 博客积分: 1577
  • 博客等级: 上尉
  • 技术积分: 476
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-01 16:40
个人简介

xxx

文章分类

全部博文(45)

文章存档

2012年(4)

2011年(14)

2010年(8)

2009年(19)

我的朋友

分类: WINDOWS

2009-11-27 19:49:52

//.h头文件
#define MAXNODE 100
#define MAX 32767
typedef  int VertexType; //顶点类型
typedef  int EdgeType;   //边,也就是路径类型
 
//////////////struct/////////////////////////
typedef struct
{
 //VertexType vexs[MAXNODE]; //顶点
 //EdgeType arcs[MAXNODE][MAXNODE]; //边,也就是路径
 VertexType *vexs; //顶点的指针定义
 EdgeType (*arcs)[MAXNODE];  //边的指针定义
 int vexnum;//顶点个数
 int arcnum;//边的条数
}MGraph;

class CGraph 
{
public:
 MGraph G;
 BOOL P[MAXNODE][MAXNODE][MAXNODE];
public:
 void BubbleSort();//用this指针实现
 void BubbleSort(CGraph *graph);//直接传递对象地址
 void CGraph::BubbleSort(int null);
 CGraph();
 virtual ~CGraph();
 void ShortestPathFloyd();
};
//cpp文件,以冒泡排序法为例
void CGraph::BubbleSort(CGraph *graph)//用传递对象的地址实现
{
 VertexType cache=0;
 for(int i=1;i {
  int flag=0;
  for(int j=0;j  {
   if(*(graph->G.vexs+j)>*(graph->G.vexs+j+1))
   {
    flag=1;
    cache=*(graph->G.vexs+j);
    *(graph->G.vexs+j)=*(graph->G.vexs+j+1);
    *(graph->G.vexs+j+1)=cache;
   }
  }
  if(0==flag)
   break;
 }
}

void CGraph::BubbleSort()//用this指针实现
{
 VertexType cache=0;
 for(int i=1;i {
  int flag=0;
  for(int j=0;j  {
   if(*(this->G.vexs+j)>*(this->G.vexs+j+1))
   {
    flag=1;
    cache=*(this->G.vexs+j);
    *(this->G.vexs+j)=*(this->G.vexs+j+1);
    *(this->G.vexs+j+1)=cache;
   }
  }
  if(0==flag)
   break;
 }
}
void CGraph::BubbleSort(int null)//将对象指针隐藏
{
 VertexType cache=0;
 for(int i=1;i {
  int flag=0;
  for(int j=0;j  {
   if(*(G.vexs+j)>*(G.vexs+j+1))
   {
    flag=1;
    cache=*(G.vexs+j);
    *(G.vexs+j)=*(G.vexs+j+1);
    *(G.vexs+j+1)=cache;
   }
  }
  if(0==flag)
   break;
 }
}
 
以上三种写法都正确
阅读(2030) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~