## 1.建表

typedef struct Node{int data;struct Node*next;}Node;Node*CreateList(Node*L,int n){L=malloc(sizeof(Node*));L->next=NULL;//初始化Node*p;srand((unsigned)time(0));for(int i=0;i<n;i++){p=malloc(sizeof(Node*));p->data=rand()%100;p->next=L->next;L->next=p;}return L;}

## 2.读数据

int Get(Node*L,int i,int *e){Node*p=L->next;int j=1;while(j<i&&p){p=p->next;++j;}*e=p->data;return *e;}

## 3.插入数据

void InsertList(Node*L,int i,int e){Node*p=L;int j=1;while(p&&j<i){p=p->next;++j;}Node*s=malloc(sizeof(Node));s->data=e;s->next=p->next;p->next=s;}

## 4.删除数据

void DeleteList(Node*L,int i){Node*p=L;int j=1;while(p&&j<i){p=p->next;++j;}Node*q=p->next;p->next=q->next;free(q);}

## 5.将表清空

void ClearList(Node*L){Node*p=L->next,*q;while(p){q=p->next;free(p);p=q;}L->next=NULL;//头结点指针域为空}

## 6.调用链表

int main(){  Node* L = NULL;  int n = 10;  L = CreateList(L, n);  int e = 0;  for (int i = 1; i <=n; i++)  {    e = Get(L, i, &e);    printf("%d ", e);  }  //插入数据  InsertList(L, 1, 20);  printf("\n");  for (int i = 1; i <=n+1; i++)  {    e = Get(L, i, &e);    printf("%d ", e);  }  //删除数据  DeleteList(L, 1, 20);    printf("\n");  for (int i = 1; i <=n; i++)  {    e = Get(L, i, &e);    printf("%d ", e);  }  //清空链表  //ClearList(L);  return 0;}

## 7.全部代码：

#include<stdio.h>#include<malloc.h>#include<time.h>#include<stdlib.h>typedef struct Node{  int data;  struct Node* next;}Node;Node* CreateList(Node* L, int n){  L = malloc(sizeof(Node*));  L->next = NULL;//初始化  Node* p;  srand((unsigned)time(0));  for (int i = 0; i < n; i++)  {    p = malloc(sizeof(Node*));    p->data = rand() % 100;      p->next = L->next;    L->next = p;  }  return L;}int Get(Node* L, int i, int* e){  Node* p = L->next;  int j = 1;  while (j < i && p)  {    p = p->next;    ++j;  }  *e = p->data;  return *e;}void InsertList(Node* L, int i, int e){  Node* p = L;  int j = 1;  while (p && j < i)  {    p = p->next;    ++j;  }  Node* s = malloc(sizeof(Node));  s->data = e;  s->next = p->next;  p->next = s;}void DeleteList(Node* L, int i){  Node* p = L;  int j = 1;  while (p && j < i)  {    p = p->next;    ++j;  }  Node* q = p->next;  p->next = q->next;  free(q);}void ClearList(Node* L){  Node* p = L->next, * q;  while (p)  {    q = p->next;    free(p);    p = q;  }  L->next = NULL;//头结点指针域为空}int main(){  Node* L = NULL;  int n = 10;  L = CreateList(L, n);  int e = 0;  for (int i = 1; i <=n; i++)  {    e = Get(L, i, &e);    printf("%d ", e);  }  //插入数据  InsertList(L, 1, 20);  printf("\n");  for (int i = 1; i <=n+1; i++)  {    e = Get(L, i, &e);    printf("%d ", e);  }  //删除数据  DeleteList(L, 1, 20);    printf("\n");  for (int i = 1; i <=n; i++)  {    e = Get(L, i, &e);    printf("%d ", e);  }  //清空链表  //ClearList(L);  return 0;}