#include <stdio.h>
#include <stdlib.h>
#define MAX_VERTEX_NUM 20
//弧结点
//弧结点结构
//[tailvex | headvex | G.xlist[x].firstIn | G.xlist[x].firstOut]
typedef struct ArcBox{
int tailvex,headvex;
struct ArcBox *hlink,*tlink;
//InfoType *info;
}ArcBox;
//头结点
typedef char VertexType;
typedef struct{
VertexType data;
int weight; //权
ArcBox *firstIn,*firstOut;
}VexNode;
typedef struct{
VexNode xlist[MAX_VERTEX_NUM];
int vexnum,arcnum;
}OLGraph;
void CreateOLGraph(OLGraph &G);
int LocateVex(OLGraph G,char u);
void main()
{
OLGraph G;
CreateOLGraph(G);
}
void CreateOLGraph(OLGraph &G)
{
printf("Input vexnum,arcnum:/n");
scanf("%d,%d",&G.vexnum,&G.arcnum);
for(int ix=0; ix<G.vexnum; ++ix)
{
int index=ix+1;
printf("Input the %dth data and weight/n",index);
fflush(stdin);
scanf("%c,%d",&G.xlist[ix].data,&G.xlist[ix].weight);
G.xlist[ix].firstIn = NULL;
G.xlist[ix].firstOut = NULL;
}
for(int arc=0; arc<G.arcnum; ++arc)
{
char v1,v2;
printf("Input <v1,v2>/n");
fflush(stdin);
scanf("%c,%c",&v1,&v2);
int i = LocateVex(G,v1);
int j = LocateVex(G,v2);
ArcBox *p=(ArcBox*)malloc(sizeof(ArcBox));
p->tailvex = i;
p->headvex = j;
p->hlink = G.xlist[j].firstIn;
p->tlink = G.xlist[i].firstOut;
G.xlist[j].firstIn = p;
G.xlist[i].firstOut = p;
}
}
int LocateVex(OLGraph G,char u)
{
int ix;
for(ix=0; ix<G.vexnum; ++ix)
{
if(u == G.xlist[ix].data) return ix;
}
if(ix == G.vexnum)
{
printf("Input error!");
exit(-1);
}
return 0;
}