Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2352074
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:07:05

#include"iostream.h"
#define Max_vertex_num 10
#define null 0
typedef char Infor;
typedef char vertex;
//---------------------------------------------------
typedef struct node
{
struct node *headlink,*taillink;
int tailver,headver;
Infor infor;
}Arcbox;
typedef struct vernode
{
Arcbox *firstint,*firstout;
vertype vertex;
}Vernode;
typedef struct
{
Vernode xlist[Max_vertex_num];
int vernum,arcnum;
}OLGragh;
//-------------------------------------------------------
void creat_OLGragh(OLGragh *G){
   int i,j,k;
   Arcbox p;
   cout<<"请输入顶点数和边数"<   cout<<"please get the vernum :";
   cin>>G->vernum;
   cout<<"please get the arcnum :";
   cin>>G->arcnum;
   for(i=0;ivernum;i++)
{
cin>>G->xlist[i].vertex;
G->xlist[i].firstint=G->xlist[i].out=null;
}

   for(k=0;karcnum;k++)
   {
   cout<<"please get the first vextex:";
           cin>>v1;//输入始点;
           cout<<"please get the second vextex:";
           cin>>v2;//输入顶点;
   i=place(G,v1);
   j=place(G,v2);
   p=new Arcbox;
           p->tailvex=i;
           p->headvex=j;
           cin>>p->infor;
           p->taillink=G->xlist[i].firstout;
           G->xlist[i].firstout=p;
           p->headlink=G->xlist[j].firstint;
           G->xlist[j].firstint=p;

   }
}
//-----------------------------------------------------------
int place(OLGragh *G,char v)
{
int k;

if(G->xlist[k].vextex==v)
return k;
}
//-----------------------------------------------------------
void main()
{
OLGragh *G;
create_OLGragh(&G)
}
//------------------------------------------------------------


--------------------next---------------------
#include"iostream.h"
#define Max_vertex_num 10
#define null 0

//---------------------------------------------------


struct Arcbox
{
Arcbox *taillink,*headlink;

int tailver,headver;
char infor;
};
struct Vernode
{
Arcbox *firstint,*firstout;
char vertex;
};
struct OLGragh
{
Vernode xlist[Max_vertex_num];
int vernum,arcnum;
};
//-------------------------------------------------------
int place(OLGragh *G,char v,int k);
void create_OLGragh(OLGragh *G){
   int i,j,k;
   char v1,v2;
   Arcbox *p;
   cout<<"请输入顶点数和边数"<   cout<<"please get the vernum :";
   cin>>G->vernum;
   cout<<"please get the arcnum :";
   cin>>G->arcnum;
   for(i=0;ivernum;i++)
{
cin>>G->xlist[i].vertex;
G->xlist[i].firstint=G->xlist[i].firstout=null;
}

   for(k=0;karcnum;k++)
   {
   cout<<"please get the first vextex:";
           cin>>v1;//输入始点;
           cout<<"please get the second vextex:";
           cin>>v2;//输入顶点;
   i=place(G,v1,k);
   j=place(G,v2,k);
   p=new Arcbox();
           p->tailver=i;
           p->headver=j;
           cin>>p->infor;
           p->taillink=G->xlist[i].firstout;
           G->xlist[i].firstout=p;
           p->headlink=G->xlist[j].firstint;
           G->xlist[j].firstint=p;

   }
}
//-----------------------------------------------------------
int place(OLGragh *G,char v,int k)
{


if(G->xlist[k].vertex==v)
return k;
}
//-----------------------------------------------------------

void create_OLGragh(OLGragh *G);

void main()
{
OLGragh G;
create_OLGragh(&G);
}
//------------------------------------

--------------------next---------------------

阅读(1278) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~