知识大全 数据结构考研分类复习真题 第七章 图[25]

Posted

篇首语:不患人之不己知,患不知人也。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 数据结构考研分类复习真题 第七章 图[25]相关的知识,希望对你有一定的参考价值。

   .假设给定的有向图是用邻接表表示 作为输入的是图中顶点个数n和边的个数m 以及图的m条边 在下面的程序中 我们用readdata程序过程输入图的信息 并建立该图的邻接表 利用topol程序过程获得图中顶点的一个拓扑序列

  PROGRAM  topol_order(input output) ;  CONST  maxn= ;  TYPE  nodeptr=^nltype ;  nltype=RECORD num : integer ; link : nodeptr  END ;  chtype=RECORD count : integer ;  head : nodeptr  END ;  VAR  ch : ARRAY [ maxn]  OF  chtype ; m n top : integer  ;  PROCEDURE  readdata  ;  VAR  i j u v : integer ;   p : nodeptr  ;  BEGIN  write (′input  vertex  number  n= ′); readln (n) ;  write (′input  edge  number  m= ′); readln(m) ;  FOR  i:= TO n DO BEGIN ch[i] count:= ; ch[i] head:=NIL  END;  writeln(′input  edges  :′);  FOR  j:=   TO  m  DO  BEGIN  write( j : ′: ′) ;  readln( u v ) ;  new( p ) ;  ch[v] count:=ch[v] count+ ; p^ num:=v; ( ) ___ ; ( ) __;  END  END ;  PROCEDURE  topol ;  VAR  i j k: integer;  t: nodeptr ;  BEGIN  top:= ;  FOR  i :=   TO n  DO  IF  ch[i] count=   THEN  BEGIN ch[i] count := top ;top := i END;  i:= ;  WHILE ( ) ___ DO  BEGIN ( ) __;    ( ) __ ; write(j : ) ;i:= i + ;t:=ch[j] head ;  WHILE  t<>NIL  DO  BEGIN k := t^ num ; ch[k] count:=ch[k] count ;  IF ch[k] count= THEN  BEGIN ch[k] count:=top; top:=k  END;  ( ) ______ ;  END  END ;  writeln;  IF i<n THEN  writeln (′the neork has a cycle!′)  END;  BEGIN  readdata ;  writeln (′output  topol  order : ′);  topol  END   【复旦大学 三 ( 分)】

cha138/Article/program/sjjg/201311/23114

相关参考