链表的值是另一个链表
简单来说就是一个索引表,以前做题的时候,完成了的。这不……前几天完成通用链表,就想着,用这组函数来重新写。
结果卡住了,打印出来的值是是乱码(好吧,也不是太乱):
21:00
问题已经被修正,现在可以正常运行了。
这并不是一个完善的索引表,因为并不检查输入的数据是否是合法的单词。
List.h 的声明和实现文件在下面的连接里可以找到。
https://bbs.bccn.net/viewthread.php?tid=476405&page=1&extra=page%3D1#pid2625770
程序代码:/*打印效果 if ok and jack witch where balck andy way for of zippo oxford english chinese dictionary cell element new learner a: and andy b: balck c: cell chinese d: dictionary e: element english f: for i: if j: jack l: learner n: new o: of ok oxford w: way where witch z: zippo */
程序代码:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "d:\mylib\list.h"
#include "d:\mylib\getstring.h"
#define MAXLINE 101
int
com1( void *, void * );
int
com2( void *, void * );
void
Print1( void * );
void
Print2( void * );
int
main( void )
{
List_T_P Root;
List_T_P C_Root;
List_T_P Temp, Head;
List_T Value;
char *Line;
char ch;
Root = NULL;
while( NULL != ( Line = getword( stdin ) ) )
{
ch = tolower( Line[ 0 ] );
if( NULL == ( Value.Element = malloc( sizeof( char ) ) ) )
exit( EXIT_FAILURE );
Value.Link = NULL;
memmove( Value.Element, &ch, sizeof( char ) );
if( NULL == ( C_Root = Find( Root, &Value, com1 ) ) )
{
Insert( &Root, &Value, sizeof( List_T ), com1 );
C_Root = Find( Root, &Value, com1 );
}
else
free( Value.Element );
Temp = ( List_T_P )( C_Root->Element );
if( NULL == Find( Temp->Link, Line, com2 ) )
Insert( &Temp->Link, Line, strlen( Line ) + 1, com2 );
free( Line );
}
Print( Root, Print1 );
while( NULL != ( Head = First( Root ) ) )
{
Temp = ( List_T_P )Head->Element;
Delete( &Temp->Link );
DelFirst( &Root );
}
return 0;
}
int
com1( void *a, void *b )
{
List_T_P A, B;
char *ch1, *ch2;
A = ( List_T_P )a;
B = ( List_T_P )b;
ch1 = ( char * )(A->Element);
ch2 = ( char * )(B->Element);
return *ch2 - *ch1;
}
int
com2( void *a, void *b )
{
return strcmp( ( char * )b, ( char * )a );
}
void
Print1( void *a )
{
List_T_P A;
A = ( List_T_P )a;
printf( "\n%c:\n",*( ( char * )( A->Element ) ) );
Print( A->Link, Print2 );
}
void
Print2( void *a )
{
printf( "%s\n", ( char * )a );
}
[此贴子已经被作者于2017-4-29 18:27编辑过]










