intJudgeLinkListIsEmpty(LinkList *L){JudgePointerNull(L);if(L->ElemArrayLen ==0){printf("Link List Is Empty\n");PrintPretty();return SuccessFlag;}else{printf("Link List Is Not Empty\n");PrintPretty();return FailFlag;}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(2)参数说明
参数名
说明
L
需要判断非空的链式表指针。
4、销毁链式表
(1)函数定义
voidDestroyLinkList(LinkList *L){printf("Start Destroy Link List\n");JudgePointerNull(L);
ElemType *p = L->ElemArray;
ElemType *q =NULL;while(p){
q = p->NextPointer;printf("Free Pointer : %p\n",p);free(p);
p = q;}free(L);printf("Free Link List Pointer: %p\n",L);
L =NULL;printf("Destroy Link List Success !!!\n");PrintPretty();}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(2)参数说明
参数名
说明
L
需要销毁的链式表指针。
5、清理链式表数据层
(1)函数定义
Status ClearLinkListElem(LinkList *L){printf("Start Clear Link List Elem\n");JudgePointerNull(L);
L->ElemArrayLen =0;
ElemType *p = L->ElemArray->NextPointer;
ElemType *q =NULL;while(p){
q = p->NextPointer;printf("Free Pointer : %p\n",p);free(p);
p = q;}
L->ElemArray->NextPointer =NULL;printf("Clear Link List Elem Success !!!\n");PrintPretty();return SuccessFlag;}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(2)参数说明
参数名
说明
L
需要清理的链式表指针。
6、获取链式表长度
(1)函数定义
intGetLinkListLen(LinkList *L){JudgePointerNull(L);printf("Get Link List Len : %d\n",L->ElemArrayLen);PrintPretty();return L->ElemArrayLen;}
CC = gcc
CFLAG_EXEC =-Wall-g
CFLAG_ALIAS =-o
RM_COMM =rm-rf
all : main
main :$(CC)$(CFLAG_EXEC) LinearTable_LinkList.c main.c $(CFLAG_ALIAS) Test_LinearTable_LinkList
clean :$(RM_COMM) Test_LinearTable_LinkList
1
2
3
4
5
6
7
8
9
10
11
12
13
四、编译运行
[gbase@czg2 LinearTable_LinkList]$ make clean
rm-rf Test_LinearTable_LinkList
[gbase@czg2 LinearTable_LinkList]$ make
gcc -Wall-g LinearTable_LinkList.c main.c -o Test_LinearTable_LinkList
[gbase@czg2 LinearTable_LinkList]$ ./Test_LinearTable_LinkList
Init ElemType Success
*********************************
Init LinkList Success
*********************************
Print Link List
Link List Pointer : 0x16c0010
################
CurrentPointer : 0x16c0060
StudentNum :
StudentName :
StudentScore :0
NextPointer :(nil)################
ElemArrayLen :0
*********************************
Error ElemPosition :1, Need 1<= ElemPosition <= ElemArrayLen(0)
*********************************
Print Elem Type
StudentNum :
StudentName :
StudentScore :0
NextPointer :(nil)
*********************************
Link List Is Empty
*********************************
Get Link List Len :0
*********************************
Start Clear Link List Elem
Clear Link List Elem Success !!!
*********************************
Print Link List
Link List Pointer : 0x16c0010
################
CurrentPointer : 0x16c0060
StudentNum :
StudentName :
StudentScore :0
NextPointer :(nil)################
ElemArrayLen :0
*********************************
Start Destroy Link List
Free Pointer : 0x16c0060
Free Link List Pointer: 0x16c0010
Destroy Link List Success !!!
*********************************