d.cd[ --d.start ] = _9__; c = f; ___10___; }
__11_____= d; }
printf( \huffman:\\n\ ); for( i = 0; i < n; i++ ) {
printf( \
for( k = hcd[i].start; k < n; k++ ) printf(\%c\ printf( \ ); } }
52
ʵ9 ͼĻ
ġο
11 2 ͼ #include
#include
/* ڽӶ */
/* ڽӱ */
}edgeNode;
typedef edgeNode *lgraph[MAX];
typedef int mgraph[MAX][MAX]; /* ڽӾ */ int visited[MAX]; /* ʱ־ */ int queue[MAX]; /* ȱ洢 */
int creat_graph( lgraph lg, mgraph mg ) /* ͼı, ͼڽӱ, ڽӾ */ {
int vn, en, k, i, j;
edgeNode *p;
printf( \ڽӱʽͼ\\n\ while( 1 ) { /* ͼĶ, */
vn = en = 0;
printf( \ͼĶ[1-30]\\n\ );
fflush( stdin );
scanf( \%d\if( ____1_____ ) continue;
printf( \ͼı[0-%d]\\n\scanf( \%d\
if( en >= 0 &&___2______ ) break; }
for( k = 0; k < vn; k++ ) lg[k] =__3___; /* ÿڽӱ */
53
for( k = 0; k < vn; k++ ) /* ÿڽӾ */
for( i = 0; i < vn; i++ ) _____4___; for( k = 0; k < en; ) { /* ڽӱ, ڽӾĸ */ i = j = -1; printf( \[%d][1-%d]: \, k+1, vn ); scanf( \%d%d\, &j );
if( i < 1 || j < 1 || i > vn || j > vn ) {
printf( \, ߷ΧΪ[1-%d]\\n\, vn );
continue;
} k++; i--;
j--; p = (edgeNode *)malloc( sizeof(edgeNode) ); ____5_____; p->next = lg[i];
lg[i] =___6__; /* ½뵽iڽӱ */ p = (edgeNode *)malloc( sizeof(edgeNode) ); p->vno = i; __7_____; lg[j] = p; /* ½뵽jڽӱ */ mg[i][j] =__8____ = 1; /* ڽӾֵ */
}
return vn; }
void ldfs( lgraph g, int i ) /* ڽӱʾͼĵݹȱ */
{ edgeNode *t;
printf( \ /* ʶi */
visited[_9_] = 1;
/* iѱ */
t = g[i];
while( t != NULL ) { /* 붥iڽӵĶ */ if( ___10____ ) /* öδʹ */
ldfs( g, t->vno ); /* ڽӶ */
_____11____; /* һڽӶ */
} }
54
void mdfs( mgraph g, int i, int vn ) /* ڽӾʾͼĵݹȱ */ { int j; printf( \ /* ʶi */ visited[i] = 1; /* iѱ */ for( j = 0; j < vn; j++ ) { /* 붥iڽӵĶ */ if( ___12____ &&__13_____ ) /* öбδʹ */
mdfs( g, j, vn ); /* ڽӶ */
}
}
void lbfs( lgraph g, int s, int n ) /* ڽӱʾͼĹȱ */ { int i, v, w, head, tail; edgeNode *t; for( i = 0; i < n; i++ ) visited[i] = 0; /* ȫΪδʱ־ */ head = tail = 0; /* ÿ */ printf( \/* ʳ */ visited[s] = 1; /* øöѱʱ־ */ queue[ __14____ ] = s; /* */ while( head < tail ) { /* Ӳѭ */ v = queue[__15___ ]; /* ȡ */ for( t = g[v]; t != NULL; t = t->next ) { /* ڽӱ, ˳붥vڽӵĸw */ w =__16___;
if( visited[w] == 0 ) { /* wδʹ */ printf( \/* ʶw */ __17_____; /* öwѱʱ־ */ queue[tail++] = w; /* w */
}
}
} }
void mbfs( mgraph g, int s, int n ) /* ڽӾʾͼĹȱ */ { int i, j, v, head, tail; for( i = 0; i < n; i++ )
visited[i] = 0;
/* ȫΪδʱ־ */
55