数学建模社区-数学中国
标题:
急求一个Fleury
[打印本页]
作者:
xinzhiyong
时间:
2009-7-17 10:26
标题:
急求一个Fleury
急求一个Fleury算法,求高手来个程序
作者:
lyyy
时间:
2009-7-17 12:23
网上有一些程序代码。
作者:
小旋风假
时间:
2009-8-23 08:57
没有看懂………………
作者:
夕夕多
时间:
2010-5-8 22:58
#include <stdio.h>
# G- B" ]7 R8 O" s9 K! @
#include <string.h>
! I! d( I0 ?( r+ b
struct stack
& s5 \* o! X0 `1 W: G
{int top , node[210];} f; //顶点的堆栈
- W+ P% \3 H c5 n; A8 s/ a
int a[201][201]; //图的邻接矩阵
$ V2 U6 B6 n! | P) H4 k! ^& Q% _
int n;
7 k- M4 P) Z& n) W
void dfs(int x) //图的深度优先遍历
: a& F& V' ^- s6 g5 H
{int i;
' R# q0 D+ f" [- u, U
f.top ++; f.node[f.top] = x;
- K, S* M% ^5 G0 ?. C) J
for (i = 1; i <= n; i ++)
; f, b1 h' x0 q! u3 E. Z
if (a[i][x] > 0)
( w! ]0 n# q' [& \: L
{ a[i][x] = 0; a[x][i] = 0; //删除此边
! a8 D( U5 H0 z1 u( a
dfs(i);
" w& ~3 L# B9 P' q0 v
break; }
3 e. j5 y' L9 B6 B1 ]
}
, m% H( @: _5 V+ ?- E2 L
void Euler(int x) //欧拉路算法
5 t1 a# u+ }& @3 h6 {2 s
{int i , b;
! K: u. h7 B2 c* w( D* u
f.top = 0; f.node[f.top] = x; //入栈
6 g* r& B% h9 W9 f! |" |: }
while (f.top >= 0)
7 Z' J7 T' z( G& ]* f7 ?* o4 `6 |
{b = 0;
- T7 y6 D' F* N' l9 Y- _7 a. Q
for (i = 1; i <= n; i ++)
" L$ I- A+ V" V5 |* X' G3 O3 O
if (a[f.node[f.top]][i] > 0)
/ r6 A' {9 t* c, E0 p& f
{b = 1; break;}
3 f {4 x% H+ ~& k& L
if (b == 0) //如果没有点可以扩展,输出并出栈
) L" l3 P: r# \8 |2 ^# I
{ printf("%d " , f.node[f.top]);
0 Y% }: [# v4 K: M. v/ t
f.top --;}
2 `" t4 N+ P* d- i" a
else {f.top --; dfs(f.node[f.top+1]);} //如果有,就DFS
3 L" L! }# W9 Q% b- G* K
}
8 C5 D7 a6 d4 b6 b5 g+ o
}
- o" s) M8 n; e4 u' R9 {% B
int main()
$ N. ^* p" _* B
{
3 e7 I& h) \' z) L5 F
int m , s , t , num , i , j , start;
x) S1 T" f$ o. u/ S
//input
9 m: z7 n2 Y4 c/ m( f5 L
scanf("%d %d" , &n , &m); //n顶点数 m边数
$ T3 z! u# X' `: w/ k/ {+ R; q
memset(a , 0 , sizeof(a));
; K7 \3 w; h# z6 S* s: `/ Q2 c
for (i = 0; i < m; i ++)
7 S5 p- k+ t9 `9 T% ]
{printf("innput s,t");
. {6 v! j; K9 B; I" W% [3 D! v) e
scanf("%d %d" , &s , &t);
; g6 n; D- C0 [9 M2 J( b% a- r
a[s][t] = 1; a[t][s] = 1;
4 E4 _9 `8 K3 r! w' E) W( W% ]2 t
}
; ` [) N$ d) Q1 [' X/ @. n/ j2 R) p
//判断是否存在欧拉回路
x. m9 \7 ]: ]0 C/ p
s = 0; start = 1;
8 }* L* f0 h! a0 }4 x
for (i = 1; i <= n; i ++)
2 k/ O( V5 }5 L% r+ L1 C7 `' i5 Y
{num = 0;
9 |, _! L6 Q5 t8 t/ n7 u
for (j = 1; j <= n; j ++)
% i0 K7 w& _3 ^& b
num += a[i][j];
2 {% F! B! f8 F: n
if (num % 2 == 1)
+ B- k0 B; }3 t) C
{start = i; s ++;}
4 {; n9 ]' z3 t. o4 q9 }
}
, G% Z" X' q: y7 l5 l( g
if ((s == 0) || (s == 2))
3 x9 d( @( Q# X+ w5 y; f9 e1 N- R
Euler(start);
' t, _3 Z5 s8 a& u/ N C% I
else printf("No Euler path\n");
! [1 ~4 @' b! i' c: M* c7 |
getchar(); getchar();
4 H5 R3 X# M* s; ^6 F' H
return 0; }
作者:
parkshinyang
时间:
2012-7-9 00:28
诶 有么有 matlab版的
作者:
屋顶风影
时间:
2013-7-28 22:06
没有matlab版本的吗
1 X9 S% o9 a# f) t: |
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5