#include <stdio.h>
#include <stdlib.h>
struct node
{
int num;
struct node * next;
};
typedef struct node Node;
typedef struct node * Link;
void create_link(Link * head)
{
*head = NULL;
}
void display_node(Link head)
{
Link tmp;
tmp = head;
while(tmp != NULL)
{
printf("num = %d\n",tmp->num);
tmp = tmp->next;
}
}
void is_malloc_ok(Link new_node)
{
if(new_node == NULL)
{
printf("malloc error!\n");
exit(-1);
}
}
void create_newnode(Link * new_node)
{
*new_node = (Link) malloc(sizeof(Node));
is_malloc_ok(*new_node);
}
void insert_node_tail(Link *head,Link new_node)
{
Link tmp;
tmp = *head;
if(*head == NULL)
{
new_node->next = *head;
*head = new_node;
}
else
{
while(tmp->next != NULL)
{
tmp = tmp->next;
}
tmp->next = new_node;
new_node->next = NULL;
}
}
int main()
{
Link head = NULL;
Link new_node = NULL;
int i;
int num;
create_link(&head);
for(i = 0; i < 10;i++)
{
create_newnode(&new_node);
new_node->num = i;
insert_node_tail(&head,new_node);
}
delete_node(&head,num);
display_node(head);
return 0;
}
#include <stdlib.h>
struct node
{
int num;
struct node * next;
};
typedef struct node Node;
typedef struct node * Link;
void create_link(Link * head)
{
*head = NULL;
}
void display_node(Link head)
{
Link tmp;
tmp = head;
while(tmp != NULL)
{
printf("num = %d\n",tmp->num);
tmp = tmp->next;
}
}
void is_malloc_ok(Link new_node)
{
if(new_node == NULL)
{
printf("malloc error!\n");
exit(-1);
}
}
void create_newnode(Link * new_node)
{
*new_node = (Link) malloc(sizeof(Node));
is_malloc_ok(*new_node);
}
void insert_node_tail(Link *head,Link new_node)
{
Link tmp;
tmp = *head;
if(*head == NULL)
{
new_node->next = *head;
*head = new_node;
}
else
{
while(tmp->next != NULL)
{
tmp = tmp->next;
}
tmp->next = new_node;
new_node->next = NULL;
}
}
int main()
{
Link head = NULL;
Link new_node = NULL;
int i;
int num;
create_link(&head);
for(i = 0; i < 10;i++)
{
create_newnode(&new_node);
new_node->num = i;
insert_node_tail(&head,new_node);
}
delete_node(&head,num);
display_node(head);
return 0;
}