C语言初始化单链表!

来源:百度知道 编辑:UC知道 时间:2024/05/15 08:13:54
哪位高手给写个初始化单链表的函数,越详细越好!!

————
为什么我感觉定义单链表可以不用头指针啊?

在单链表A中删除所有和单链表B中元素相同的结点

#include "stdafx.h"
#include <stdio.h>
#include <malloc.h>
#define SIZE sizeof(struct node)
struct node{
int data;
struct node *next;
};

void init(struct node *LC){

int n;
struct node *Str,*p;
p=(struct node *)malloc(SIZE);
Str=LC;
printf("请输入链表A,以小于零的数结束输入:\n");
scanf("%d",&n);
while(n>=0){
p->data=n;
Str->next=p;
Str=p;
p=(struct node *)malloc(SIZE);
scanf("%d",&n);
Str->next=NULL;
}
printf("您输入的序列的是:\n");
for (Str=LC->next;Str!=NULL;){
printf("%d ",Str->data);
Str=Str->next;
}
printf("\n");

}

void delet_LA(struct node *LA,struct node *pa){
struct node *p;
struct node *q;
p=LA;
q=p;
for (p;p!=pa;){<