<span style="font-size:24px;">
#include<stdio.h>
#include<malloc.h>
typedef struct nnode{
int data;
struct nnode* link;}node;
node* create_list(int n);
void printf_list(node *p_head);
void insert_node(node *p_head,int val_data);
void add_node(node *p_head,int val_data);
void delete_node(node *head,node *p_head);
int main()
{
node *head;
head=create_list(4);
printf_list(head);
add_node(head,4);
printf_list(head);
insert_node(head->link,0);
printf_list(head);
delete_node(head,head->link->link);
printf_list(head);
return 0;
}
//create an n nodes list
node* create_list(int n)
{
int i;
node *head,*p,*q; //if no head,we cann't return the adress of list head
head =(node *)malloc(sizeof(node));
p=head;
p->data=0;
for(i=1;i<n;i++)
{
q=(node *)malloc(sizeof(node));
p->link=q;
p=q;
p->data = i;
}
q->link=NULL;
return head;
}
//printf list which head is p_head
void printf_list(node *p_head)
{
while(p_head->link != NULL)
{
printf("%d ",p_head->data);
p_head=p_head->link;
}
printf("%d\n",p_head->data);
}
//insert a node after p_head->link
void insert_node(node *p_head,int val_data)
{
node *p;
p=(node *)malloc(sizeof(node));
p->data=val_data;
p->link=p_head->link;
p_head->link=p;
}
//add anode in the list which head is p_head
void add_node(node *p_head,int val_data)
{
node *p;
p=(node *)malloc(sizeof(node));
while(p_head->link!=NULL)
p_head=p_head->link;
p_head->link=p;
p->data=val_data;
p->link=NULL;
}
//delete a node from list head in address p_head
void delete_node(node *head,node *p_head)
{
while(head->link != p_head)
head=head->link;
head->link=head->link->link;
free(p_head);
}</span>