拓撲排序程式

2021-04-14 01:08:47 字數 1365 閱讀 2700

//拓撲排序

#include

#include

#define max_vertex_num 50

#define stack_size 50

typedef struct arcnodearcnode;//鄰接表結點

typedef struct vnodevnode,adjlist[max_vertex_num];//頭結點

typedef struct algraph;//鄰接圖的資訊

typedef struct sqstack;//堆疊結構體

//*****************初始化堆疊**********************

void initstack(sqstack *s)

//*****************入棧*************************

void push(sqstack *s,int e)

//*****************出棧************************

void pop(sqstack *s,int *e)

//****************判斷棧空************************

int stackempty(sqstack *s)

//***********************建立圖******************

void creatgraph(algraph *g)

for(i=1;i<=g->arcnum;i++)

p=(arcnode *)malloc(sizeof(arcnode));//為鄰接表結點申請空間

if(!p)

exit(1);

p->adjvex=m;

p->nextarc = g->vertices[n].firstarc;//鍊錶的操作

g->vertices[n].firstarc=p;

}printf("the adjacency list :/n");

for(i=1;i<=g->vexnum;i++)//輸出此鄰接表

}//*******************求入度***************************

void findindegree(algraph g,int indegree)}}

//**********************拓撲排序***************************

void topologicalsort(algraph g)

printf("topological sort is /n");

while(!stackempty(&s)) //棧不空,出棧並輸出結果

}if(count

快速排序程式

快速排序程式 include int findpos int a,int low,int high void quicksort int a,int low,int high intmain 此處可以多試幾組資料 inti quicksort a,0,5 第二個引數表示第乙個元素的下標,第三引數表示...

快速排序程式(windows vs)

sort and count.cpp 定義控制台應用程式的入口點。pragma once include stdafx.h include include include include using namespace std int filelength 100000 int numbers 10...

演算法 「氣泡排序」程式模擬

文獻 data structures and algorithms using c michael mcmillan 平台 net 2.0 排序最基礎最基本的演算法便是氣泡排序了,bubble sort,最基本的往往最能反映排序的基本思想,基本思路,儘管它做了很多次冗餘的比較。在.net中通過ran...