每日考研数据结构的学习笔记,有得地方有错误,大家不要都看。
我想实现头插法建立单链表没有解决
错误的版本
#include<stdio.h>
#include<stdlib.h>
typedef struct LNode{
int data;
struct LNode*next;
}LNode,*LinkList;
LinkList* head(LinkList &L){
LNode*s;int x;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
scanf("%d",&x);
while(x!=9999){
s=(LNode*)malloc(sizeof(LNode));
s->next=L->next;
L->next=s;
}
return L;
}
int main(){
LinkList L;
L=head(L);
}
正确的版本
#include<stdio.h>
#include<stdlib.h>
typedef struct LNode{
int data;
struct LNode*next;
}LNode,*LinkList;
LinkList head(){
LNode*s;int x;
LinkList L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
scanf("%d",&x);
while(x!=9999){
s=(LNode*)malloc(sizeof(LNode));
s->next=L->next;
L->next=s;
}
return L;
}
int main(){
LinkList L=head();
}
但是单链表的结构体定义
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
typedef struct LNode LNode; //将结构体类型struct LNode重命名为LNode
typedef struct LNode * LinkList; //将struct LNode *重命名为LinkList
但是还没有解决为何LinkList前有 * ,但是LNode前无 * 。