带头节点链表的基本操作
#include <malloc.h>
#include <cstdio>
typedef struct LNode{
int data;
struct LNode *next;
}LNode,*LinkList;
void printDataAndLength(LinkList L){
int length = 0;
while(L != NULL){
printf("链表的值- %d \n",L->data);
L= L->next;
length ++;
}
printf("链表的长度(不带有头结点)- %d \n",length-1);
}
LinkList List_HeadInsert(LinkList &L){
LNode *s;
int x;
L=(LinkList)malloc(sizeof(LNode));
L->data = 0;
L->next = NULL;
printf("请输入链表数据: \n");
scanf("%d",&x);
while (x!=9999){
s=(LNode*)malloc(sizeof(LNode));
s->data = x;
s->next = L