本课主题: 实验二 循环链表实验
教学目的: 掌握单向链表的实现方法
教学重点: 单向链表的存储表示及操作
教学难点: 单向链表的操作实现
授课内容:
一、单向链表的存储表示
C源程序
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#define ERROR 0
#define OK 1
#define EQUAL 1
#define OVERFLOW -1
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
struct STU{
char name[20];
char stuno[10];
int age;
int score;
}stu[50];
typedef struct STU ElemType;
struct LNODE
{
ElemType data;
struct LNODE *next;
};
typedef struct LNODE LNode;
typedef struct LNODE *LinkList;
int init_L(LinkList *L)
{
*L=(LNode *)malloc(sizeof(LNode));
if(!L) exit(ERROR);
(*L)->next=NULL;
return OK;
}/*init */
int ListLength(LinkList L)
{
int j=0;
while (L->next)
{
L=L->next;
j++;
}
return j;