daimachuan

query_graph.c

#include

#include
#include
#include
#include
using namespace std;
mapVId2Label;
mapVLabel2Id;
pair::iterator,bool>Insert_Pair;
struct EdgeNode
{
string valued;
EdgeNode*next;
int adjvex;
};
struct vertexNode
{
EdgeNode*firstedge;
string data;
};
struct AdjList
{
int verNum;
int ArcNum;
vertexNode vertices[10];
};
int countnode;
void Create_GF(AdjList*G)
{
countnode=0;
int flag=0;
string x,la,y;
while(cin>>x>>la>>y)
{
int len=y.length();
if(y[len-1]=='}'){flag=1;y=y.substr(0,len-1);}
Insert_Pair=VLabel2Id.insert(pair(x,countnode));
if(Insert_Pair.second==true)
{
VId2Label.insert(pair(countnode,x));
G->vertices[countnode].firstedge=NULL;
countnode++;
}
Insert_Pair=VLabel2Id.insert(pair(y,countnode));
if(Insert_Pair.second==true)
{
VId2Label.insert(pair(countnode,y));
G->vertices[countnode].firstedge=NULL;
countnode++;
}
int st=VLabel2Id[x];
int ed=VLabel2Id[y];
EdgeNode*s=new EdgeNode;
s->valued=la;
s->adjvex=ed;
s->next=G->vertices[st].firstedge;
G->vertices[st].firstedge=s;
if(flag==1)break;
}
}
void Print_GF(AdjList *G)
{
for(int i=0;i {
cout< EdgeNode*p=G->vertices[i].firstedge;
while(p)
{
cout<<" -> "<adjvex]<<" ( BY:"<valued<<") ";
p=p->next;
}
cout< }
}
void Delete_GF(AdjList*G)
{
for(int i=0;i {
EdgeNode*q;
EdgeNode*p=G->vertices[i].firstedge;
while(p)
{
q=p;
p=p->next;
delete q;
}
G->vertices[i].firstedge=NULL;
}
}
int main()
{
char tmp;
cin>>tmp;
while(tmp!='{')cin>>tmp;
getchar();
AdjList G;
Create_GF(&G);
Print_GF(&G);
Delete_GF(&G);
}


jiantu

#include
#include
#include
#include
#include
using namespace std;
mapVId2Label;
mapVLabel2Id;
pair::iterator,bool>Insert_Pair;
struct EdgeNode
{
string valued;
EdgeNode*next;
int adjvex;
};
struct vertexNode
{
EdgeNode*firstedge;
string data;
};
struct AdjList
{
int verNum;
int ArcNum;
vertexNode vertices[10];
};
int count;
void Create_GF(AdjList*G)
{
cin>>G->verNum;
count=0;
for(int i=0;iverNum;i++)
{
cin>>G->vertices[i].data;
Insert_Pair=VLabel2Id.insert(pair(G->vertices[i].data,count));
if(Insert_Pair.second==true)
{
VId2Label.insert(pair(count,G->vertices[i].data));
count++;
}
G->vertices[i].firstedge=NULL;
}

cin>>G->ArcNum;
string x,y,la;
for(int i=0;iArcNum;i++)
{
cin>>x>>y>>la;
int st=VLabel2Id[x];
int ed=VLabel2Id[y];
EdgeNode*s=new EdgeNode;
s->valued=la;
s->adjvex=ed;
s->next=G->vertices[st].firstedge;
G->vertices[st].firstedge=s;
}
}
void Print_GF(AdjList *G)
{
for(int i=0;i{
cout<EdgeNode*p=G->vertices[i].firstedge;
while(p)
{
cout<<"->"<adjvex]<<"(BY"<valued<<") ";
p=p->next;
}
cout<}
}
void Delete_GF(AdjList*G)
{
for(int i=0;i{
EdgeNode*q;
EdgeNode*p=G->vertices[i].firstedge;
while(p)
{
q=p;
p=p->next;
delete q;
}
G->vertices[i].firstedge=NULL;
}
}
int main()
{
AdjList G;
Create_GF(&G);
Print_GF(&G);
Delete_GF(&G);
}


你可能感兴趣的:(心路日记)