Aov网络与拓补排序的实现
2014-10-24 23:15
155 查看
测试的节点分布如下:
测试代码如下:
/**
拓补排序的实现,使用邻接链表存储有向图
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAX 7+1
using namespace std;
struct node
{
int num;
struct node *next;
};
struct list
{
int key;
struct node *head;
};
struct list List[MAX];
int count[MAX];
void init()
{
struct node *point,*pre;
int m,n;
for(int i=1; i<MAX; i++)
{
List[i].key=i;
List[i].head=NULL;
}
freopen("input.txt","r",stdin);
memset(count,0,sizeof(count));
while(~scanf("%d%d",&m,&n))
{
point = (struct node *)malloc(sizeof(struct node));
point->num = n;
point->next = NULL;
count
++;
pre=List[m].head;
if(pre!=NULL)
{
while(pre->next!=NULL)
pre=pre->next;
pre->next=point;
}
else
List[m].head=point;
}
return;
}
void AOV()
{
int stack[MAX],top=-1;//用数组模拟一个栈,top为-1的时候,栈为空
struct node *current;
memset(stack,-1,sizeof(stack));
int i;
for(i=1; i<MAX; i++)
if(count[i]==0)
{
stack[++top]=i;
}
while(top>-1)
{
printf("第 %d 个节点\n",stack[top]);
//拆除节点为stack[top]的所有的相关的边,这里即相邻节点的入度减1;
current=List[stack[top]].head;
stack[top--]=-1;
while(current!=NULL)
{
count[current->num]--;
if(count[current->num]==0)
{
stack[++top]=current->num;
}
current=current->next;
}
}
return;
}
int main()
{
init();
AOV();
return 0;
}
测试结果如下:
测试代码如下:
/**
拓补排序的实现,使用邻接链表存储有向图
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAX 7+1
using namespace std;
struct node
{
int num;
struct node *next;
};
struct list
{
int key;
struct node *head;
};
struct list List[MAX];
int count[MAX];
void init()
{
struct node *point,*pre;
int m,n;
for(int i=1; i<MAX; i++)
{
List[i].key=i;
List[i].head=NULL;
}
freopen("input.txt","r",stdin);
memset(count,0,sizeof(count));
while(~scanf("%d%d",&m,&n))
{
point = (struct node *)malloc(sizeof(struct node));
point->num = n;
point->next = NULL;
count
++;
pre=List[m].head;
if(pre!=NULL)
{
while(pre->next!=NULL)
pre=pre->next;
pre->next=point;
}
else
List[m].head=point;
}
return;
}
void AOV()
{
int stack[MAX],top=-1;//用数组模拟一个栈,top为-1的时候,栈为空
struct node *current;
memset(stack,-1,sizeof(stack));
int i;
for(i=1; i<MAX; i++)
if(count[i]==0)
{
stack[++top]=i;
}
while(top>-1)
{
printf("第 %d 个节点\n",stack[top]);
//拆除节点为stack[top]的所有的相关的边,这里即相邻节点的入度减1;
current=List[stack[top]].head;
stack[top--]=-1;
while(current!=NULL)
{
count[current->num]--;
if(count[current->num]==0)
{
stack[++top]=current->num;
}
current=current->next;
}
}
return;
}
int main()
{
init();
AOV();
return 0;
}
测试结果如下:
相关文章推荐
- 采用Vivado HLS为视频处理实现中值滤波器和排序网络
- Python实现AOV网络——拓扑排序,AOE网络——关键路径
- AOV网络与拓扑(二)——实现
- 采用Vivado HLS为视频处理实现中值滤波器和排序网络
- 排序网络(Sorting network )构造的C语言实现
- 用BP网络算法实现对含噪声0到9数字的识别
- 三层结构中DBGridEh实现点击列Title排序
- 如何实现在程序中进行网络计算机的用户验证
- 原来DELPHI里面实现数据列表框的列排序是这么简单?
- 网络实现技术--IBM专有网络SNA/APPN
- 实现网络蚂蚁的实时监视剪贴板功能
- 网络积件方案(实现篇)
- 如何在ASP中实现网络打印功能
- crystal report排序功能的实现
- WINDOWS (服务器) 和 DOS(客户端) 网络互连 基于TCP/IP的编程实现
- WINDOWS (服务器) 和 DOS(客户端) 网络互连 基于TCP/IP的编程实现
- [导入]在XSLT实现按日期排序
- 用C#下的Raw Socket编程实现网络封包监视
- WINDOWS (服务器) 和 DOS(客户端) 网络互连 基于TCP/IP的编程实现
- 实现网络蚂蚁在IE中右键菜单的“用xxxxxx下载”功能