单链表的实现C语言版
线性表的第二个儿子-------------单链表
结构体如下
typedef int ElemType; typedef struct Lnode{ ElemType data; struct Lnode* next; }Lnode,*LinkLnode;
初始化链表
LinkLnode InitLnode(){ LinkLndoe p; LinkLnode temp = (LinkLnode)malloc(sizeof(Lnode)); temp->data = NULL; temp->next = NULL; P = temp; return p; }
插入链表
LinkLnode InsertLnode(LinkLnode l, int add, ElemType e){ LinkLnode temp = NULL ; temp = l; if(add<1){ printf("插入有问题"); return l; } for(int i = 1;i < add;i++){ if(temp==NULL){ printf("插入有问题"); return l; } temp = temp->next; } LinkLnode c = (LinkLnode)malloc(sizeof(Lnode)); c->data = e; c->next = temp->next; temp->next = c; return l; }