#include <stdio.h>
#include <string.h>
typedef struct L_node{
int data;
struct L_node* next;
}L_node;
L_node* make_node(int data)
{
L_node* node = (struct L_node*)malloc(sizeof(struct L_node));
if(node == NULL)
{
printf("make error\n");
return NULL;
}
node->data = data;
node->next = NULL;
return node;
}
void list_add_node_end(L_node * list, int data)
{
if(list == NULL )
{
printf("input list NULL\n");
return;
}
while(list->next)
{
list = list->next;
}
L_node* node = make_node(data);
list->next = node;
}
L_node * list_add_end(L_node * list1, L_node * list2)
{
if(list1 == NULL || list2 == NULL )
{
printf("input list NULL\n");
return;
}
L_node * cur_node = list1;
while(cur_node->next)
{
cur_node = cur_node->next;
}
cur_node->next = list2;
return list1;
}
void list_printf(L_node * list)
{
L_node * cur_node = list;
while(cur_node != NULL)
{
printf("data:%d\n",cur_node->data);
cur_node = cur_node->next;
}
}
int main () {
L_node* head_1 = make_node(0);
L_node* head_2 = make_node(5);
L_node* head_3 = NULL;
int i=0;
for(i=1 ;i<5;i++){
list_add_node_end(head_1, i);
}
for(i=6 ;i<10;i++){
list_add_node_end(head_2, i);
}
list_printf(head_1);
list_printf(head_2);
head_3 = list_add_end(head_1, head_2);
printf("----------------\n");
list_printf(head_3);
return 0;
}