链式前向星



 “链式前向星”是我创造的(至少Baidu上没有搜到)名词,或许这种数据结构有其他更加正规易懂的名字,但我还是没有搜到。(有一个资料称之为加上next数组前向星,但这个名字实在不好)

该数据结构可能是Jason911神牛或其他神牛发明的,我只是起了个名字并写了这个课件。

Malash

2009年10月18日0:34:50

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

 

链式前向星及其简单应用 - Malash - Malash的OI生涯

示例程序:
 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=Size++;
}

void Show(int u)
{
    for(int i=Adj;~i;i=E.next)
    {
        printf("%d--->%d\n",u,E.to);
    }
}

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;
}
* This source code was highlighted by YcdoiT. ( style: Codeblocks )


posted @ 2013-08-27 22:43  码代码的猿猿  阅读(411)  评论(0编辑  收藏  举报