daimachuan
2016-07-26 13:47
375 查看
query_graph.c
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<map>
#include<iostream>
using namespace std;
map<int,string>VId2Label;
map<string,int>VLabel2Id;
pair<map<string,int>::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<string,int>(x,countnode));
if(Insert_Pair.second==true)
{
VId2Label.insert(pair<int,string>(countnode,x));
G->vertices[countnode].firstedge=NULL;
countnode++;
}
Insert_Pair=VLabel2Id.insert(pair<string,int>(y,countnode));
if(Insert_Pair.second==true)
{
VId2Label.insert(pair<int,string>(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<countnode;i++)
{
cout<<VId2Label[i];
EdgeNode*p=G->vertices[i].firstedge;
while(p)
{
cout<<" -> "<<VId2Label[p->adjvex]<<" ( BY:"<<p->valued<<") ";
p=p->next;
}
cout<<endl;
}
}
void Delete_GF(AdjList*G)
{
for(int i=0;i<countnode;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<stdio.h>
#include<stdlib.h>
#include<string>
#include<map>
#include<iostream>
using namespace std;
map<int,string>VId2Label;
map<string,int>VLabel2Id;
pair<map<string,int>::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;i<G->verNum;i++)
{
cin>>G->vertices[i].data;
Insert_Pair=VLabel2Id.insert(pair<string,int>(G->vertices[i].data,count));
if(Insert_Pair.second==true)
{
VId2Label.insert(pair<int,string>(count,G->vertices[i].data));
count++;
}
G->vertices[i].firstedge=NULL;
}
cin>>G->ArcNum;
string x,y,la;
for(int i=0;i<G->ArcNum;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<count;i++)
{
cout<<VId2Label[i];
EdgeNode*p=G->vertices[i].firstedge;
while(p)
{
cout<<"->"<<VId2Label[p->adjvex]<<"(BY"<<p->valued<<") ";
p=p->next;
}
cout<<endl;
}
}
void Delete_GF(AdjList*G)
{
for(int i=0;i<count;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);
}
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<map>
#include<iostream>
using namespace std;
map<int,string>VId2Label;
map<string,int>VLabel2Id;
pair<map<string,int>::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<string,int>(x,countnode));
if(Insert_Pair.second==true)
{
VId2Label.insert(pair<int,string>(countnode,x));
G->vertices[countnode].firstedge=NULL;
countnode++;
}
Insert_Pair=VLabel2Id.insert(pair<string,int>(y,countnode));
if(Insert_Pair.second==true)
{
VId2Label.insert(pair<int,string>(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<countnode;i++)
{
cout<<VId2Label[i];
EdgeNode*p=G->vertices[i].firstedge;
while(p)
{
cout<<" -> "<<VId2Label[p->adjvex]<<" ( BY:"<<p->valued<<") ";
p=p->next;
}
cout<<endl;
}
}
void Delete_GF(AdjList*G)
{
for(int i=0;i<countnode;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<stdio.h>
#include<stdlib.h>
#include<string>
#include<map>
#include<iostream>
using namespace std;
map<int,string>VId2Label;
map<string,int>VLabel2Id;
pair<map<string,int>::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;i<G->verNum;i++)
{
cin>>G->vertices[i].data;
Insert_Pair=VLabel2Id.insert(pair<string,int>(G->vertices[i].data,count));
if(Insert_Pair.second==true)
{
VId2Label.insert(pair<int,string>(count,G->vertices[i].data));
count++;
}
G->vertices[i].firstedge=NULL;
}
cin>>G->ArcNum;
string x,y,la;
for(int i=0;i<G->ArcNum;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<count;i++)
{
cout<<VId2Label[i];
EdgeNode*p=G->vertices[i].firstedge;
while(p)
{
cout<<"->"<<VId2Label[p->adjvex]<<"(BY"<<p->valued<<") ";
p=p->next;
}
cout<<endl;
}
}
void Delete_GF(AdjList*G)
{
for(int i=0;i<count;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);
}
相关文章推荐
- 70. Climbing Stairs
- Gradle sync failed: Gradle DSL method not found: 'compile()',Consult IDE log for more details
- Doing Homework again
- saiku 修改默认图表颜色
- http://www.caogen.com/blog/Infor_detail/83263.html
- intellj vailad code
- org.hibernate.AnnotationException: No identifier specified for entity: cn.itcast.domain.Counter
- Gtk-Message: Failed to load module "canberra-gtk-module"
- opencv Haartraining
- 将GPS坐标转换成百度地图坐标,将baidu 经纬度 转换为google经纬度
- [219] Contains Duplicate II
- pthread_key泄露问题检测
- (HDU 5728)2016 Multi-University Training Contest 1 PowMod(数论)
- 1086. Tree Traversals Again (25)
- 游戏编程中的人工智能技术-扫雷机系列
- SLA by Short brain-July-2016
- 7.5 obtaining database metadata
- HDU 4300 Clairewd’s message 扩展kmp || kmp
- (LeetCode)Contains Duplicate -- 查看数组是否重复
- hihocoder #1341 Constraint Checker