//作者:Guo R.H
//日期:06.12.22
// USTC
#include
#include
#define LEN sizeof ( struct List )
struct List
{
int num;
struct List *next;
};
struct List *creat ( ) ;
struct List *delete ( struct List *head, int i) ;
void print ( struct List *head ) ;
struct List *merge(struct List *head1, struct List *head2) ;
int main( )
{
struct List *head1, *head2, *head;
head1 = creat ( );
head2 = creat ( );
head = merge(head1, head2);
print( head );
head=delete(head, 1);
print(head);
return 0;
}
struct List *creat ( )
{
struct List *head, *new, *now;
head = NULL ;
now = new = ( struct List * ) malloc( LEN ) ;
printf("Please input a number : ") ;
scanf("%d", &new->num) ;
while ( new->num != 0 )
{
if (head == NULL)
head = new ;
else
now->next = new ;
now = new ;
new = ( struct List * )malloc( LEN ) ;
printf("Please input a number : ") ;
scanf("%d", &new->num) ;
}
now->next = NULL ;
free (new);
return(head);
}
void print ( struct List *head )
{
struct List *p ;
p = head ;
if (head == NULL)
{
printf("It's a empty list.\n%d", head) ;
return ;
}
else
{
printf("The list is :\n") ;
do
{
printf("%d\n", p->num) ;
p = p->next ;
}while (p != NULL);
}
}
struct List *merge(struct List *head1, struct List *head2)
{
struct List *head, *p;
head = p = head1;
while (p->next)
p = p->next;
p->next = head2;
return head;
}
struct List *delete ( struct List *head, int i)
{
struct List *p1, *p2;
p1 = head;
while( p1->next != NULL)
{
if (p1->num == i)
{
if(p1 = head)
head = p1->next;
else
p2->next=p1->next;
}
p2 = p1;
p1 = p1->next;
}
return head;
}
阅读(1496) | 评论(1) | 转发(0) |