22:13 最终版本,如果还有BUG,也就这样了,懒得弄了。
另外附上List.h接口的实现代码,要测试的话,自己测试吧。
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
程序代码:
#include <stdio.h>
#include "List.h"
void
Merge( Node **L1, Node **L2);
int
main( void )
{
Node *L1,*L2;
int value;
L1 = NULL;
L2 = NULL;
while( 1 == scanf( "%d", &value) )
InsertList( &L1, value );
getchar();
while( 1 == scanf( "%d", &value ) )
InsertList( &L2, value );
PrintList( L1,' ' );
printf("\n");
PrintList( L2, ' ' );
printf("\n");
Merge( &L1, &L2 );
PrintList( L1, ' ' );
printf("\n");
DeleteList( &L1 );
return 0;
}
void
Merge( Node **L1, Node **L2 )
{
Node *First, *Secondary;
Node *Temp;
for( First = *L1, Secondary = *L2; NULL != First; First = *L1 )
{
for( ; NULL != Secondary && First->Value >= Secondary->Value; Secondary = Temp )
{
Temp = Secondary->Next;
*L1 = Secondary;
Secondary->Next = First;
L1 = &Secondary->Next;
}
L1 = &First->Next;
}
*L1 = Secondary;
}
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include "List.h"
int
InsertList( Node **RootP, int value )
{
Node *NewCell;
Node *Current;
while( NULL != ( Current = *RootP ) && value > Current->Value )
RootP = &Current->Next;
NewCell = (Node *)malloc( sizeof(Node) );
if( NULL == NewCell )
return 0;
NewCell->Value = value;
NewCell->Next = Current;
*RootP = NewCell;
return 1;
}
void
DeleteNode( Node **RootP , int value )
{
Node *Current;
while( NULL != ( Current = *RootP ) && value != Current->Value )
RootP = &Current->Next;
if( NULL == Current )
return;
*RootP = Current->Next;
free( Current );
}
void
PrintList( Node *RootP, char Spacech )
{
Node *Current;
while( NULL != ( Current = RootP ) )
{
printf("%d%c",Current->Value,Spacech);
RootP = Current->Next;
}
}
void
DeleteList( Node **RootP )
{
Node *Current;
Node *Temp;
Current = *RootP;
*RootP = NULL;
while( NULL != Current )
{
Temp = Current->Next;
free( Current );
Current = Temp;
}
}
Node *
FindNode( Node *Root, int value )
{
Node *Next;
while( NULL != ( Next = Root ) && Next->Value != value )
Root = Next->Next;
return Next;
}
Node *
ReverseList( Node *first )
{
Node *current;
Node *next;
for( current = NULL; NULL != first; first = next )
{
next = first->Next;
first->Next = current;
current = first;
}
return current;
}
[此贴子已经被作者于2017-3-30 05:51编辑过]