1.单链表的头文件
typedef int datatype;
typedef struck link_node{
datatype info;
struck link_node *next;
}node;
typedef node *linklist;
2.建立一个空的单链表
node *init(){
return NULL;
}
3.输出单链表的节点值
void display(node *head){
node *p;
p=head;
if(!p) printf("单链表是空的。");
else
{
printf("单链表的各个节点值为:");
while(p){
printf("%5d",p->info);
p=p->next;
}
}
}
4.单链表查找第i个节点
void *find(node *head,int i){
int j=1;
node *p=head;
if(i<0) return NULL;
while(p&&i!=j){
p=p->next;
j++;
}
return p;
}
5.单链表第i个节点后插入值为x的节点
node *insert(node *head,datatype x,int i){
node *p,*q;
q=find(head,i);
if(!q&&i!=0) printf("该节点不存在");
else
{
p=(node *)malloc(sizeof(node));
p->info=x;
if(i==0){ //插入接待你作为单链表第一个节点
p->next=head;
head=p;
}
else
{
p->next=q->next;
q->next=p;
}
}
return head;
}
6.单链表删除一个值为x的节点
node *dele(node *head,datatype x)
{
node *pre=NULL,*p;
if(!head) {printf("单链表是空的!");return head;}
p=head;
while(p&&p->info!=x)/*没有找到并且没有找完*/
{pre=p;p&#