给出下面C语言程序(单链表的插入和删除)的注释

来源:百度知道 编辑:UC知道 时间:2024/05/13 07:42:29
每一句的都要
#include <stdio.h >
#include <stdlib.h >
typedef char datatype;
typedef struct node
{
datatype data;
struct node*next;
}LinkList;
LinkList* InitList(LinkList*head)
{//初始化单链表
head=(LinkList*)malloc(sizeof(node));
head- >next=NULL;
return head;
}
LinkList* CreateList(LinkList*head,int n)
{//建立带头结点的单链表
LinkList*P,*Q;
Q=head;
int i;
for(i=0;i <n;i++)
{
P=(LinkList*)malloc(sizeof(node));//生成新结点
scanf("%c",&P- >data);
head- >next=P;\
head=P;
}
head- >next=NULL;
return head;
}
LinkList*InsertList(LinkList*head,int n,datatype x)
{//单链表的插入
LinkList*P,*Q=head;
P=(LinkList*)malloc(sizeof(node));
P- >data=x;
P- >next=NULL;
int i=0;
while(Q&&i <n)
Q=Q- >next;

P- >n

#include <stdio.h >
#include <stdlib.h >
typedef char datatype;
typedef struct node
{
datatype data;
struct node*next;
}LinkList;
LinkList* InitList(LinkList*head)
{//初始化单链表
head=(LinkList*)malloc(sizeof(node));
head- >next=NULL;
return head;
}
LinkList* CreateList(LinkList*head,int n)
{//建立带头结点的单链表
LinkList*P,*Q;
Q=head;
int i;
for(i=0;i <n;i++)
{
P=(LinkList*)malloc(sizeof(node));//生成新结点
scanf("%c",&P- >data);
head- >next=P;\
head=P;
}
head- >next=NULL;
return q; //此处应该返回q
}
LinkList*InsertList(LinkList *head,int n,datatype x)
{//单链表的插入
LinkList*P,*Q=head;
P=(LinkList*)malloc(sizeof(node));
P- >data=x;
P- >next=NULL;
int i=0;
while(Q&&i <n)
Q=Q- >next;

P- >next=Q- >next;
Q- >next=P;