这是在上数据结构课程时候的练习,以后拿过来随时用。
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
typedef int elemtype;
#define TRUE 0
#define FALSE 1
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#if(1)
typedef struct LNode
{
struct LNode *next;
int date;
}*LinkList;
//typedef LNode *LinkList;
#endif
#if(0)
typedef struct LNode
{
struct LNode *next;
elemtype data;
};
#endif
void InitList(LinkList L)
{
L = (LinkList)malloc(sizeof(struct LNode));
if(!L)
{
exit(-1);
}
L->next = NULL;
}
void DestroyList(LinkList L)
{
LinkList q;
while(L)
{
q = L->next;
free(L);
L = q;
}
}
void ClearList(LinkList L)
{
LinkList p, q;
p = L->next; //p = L的话就销毁了链表相当于DestroyList
while(p)
{
q = p->next;
free(p);
p = q;
}
L->