写法一:
int Empty(List *L)//判空
{
return L->size=0;
}
void Clear(List* L)//清表
{
while(!Empty(L))
Pop_front(L);
L->size=0;
}
void Free(List* L)//撤销所有节点空间
{
Clear(L);
free(L->head);
free(L->tail);
}
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<math.h>
typedef int Type;
struct Node
struct Node* next;
Type data;
struct Node* prev;
};
typedef struct Node Node;
typedef struct
{
Node* head;
int size;
Node* tail;
}List;
int main()
{
List L;
Init(&L);//中间还有对链表的一系列操作如前插,前删等
Free(&L);
return 0;
}
写法二:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<math.h>
typedef int Type;
struct Node
{
struct Node* next;
Type data;
struct Node* prev;
};
typedef struct Node Node;
typedef struct
{
Node* head;
int size;
Node* tail;
}List;
int main()
{
List L;
Init(&L);//中间还有对链表的一系列操作如前插,前删等
free(L.tail);
free(L.head);
L.head=NULL;
L.tail=NULL;
L.size=0;
return 0;
}
PIPIONE
相关分类