“链式前向星”是我创造的(至少Baidu上没有搜到)名词,或许这种数据结构有其他更加正规易懂的名字,但我还是没有搜到。(有一个资料称之为加上next数组前向星,但这个名字实在不好)
该数据结构可能是Jason911神牛或其他神牛发明的,我只是起了个名字并写了这个课件。
Malash
2009年10月18日0:34:50
示例程序:
7
1 2
2 3
3 4
1 3
4 1
1 5
4 5
#include <iostream> #include <cstring> #include <cstdio> using namespace std; const int MaxV=1000; const int MaxE=10000; typedef struct node { int to; int next; }Edge; Edge E[MaxE]; int Adj[MaxV]; int Size; void Init() { Size=0; memset(Adj,-1,sizeof(Adj)); } void Add_Edge(int u,int v) { E[Size].to=v; E[Size].next=Adj Adj } void Show(int u) { for(int i=Adj { printf("%d--->%d ",u,E } } int main() { int m; cin>>m; Init(); while(m--) { int a,b; cin>>a>>b; Add_Edge(a,b); } for(int i=1;i<=5;i++) { Show(i); } return 0; } |