代码实现
st_dataNode* searchListNode(st_dataNode* head, int num){
if(NULL == head){
return NULL;
}
st_dataNode* p = NULL;
st_dataNode* q = NULL;
p = head;
while(NULL != p){
if(p->data == num){
q = p;
break;
}
p = p->next;
}
return q;
}
void testSearchList(void){
st_dataNode * rst = NULL;
rst = searchListNode(ghead, 6);
if(NULL != rst){
printf("node: %p, data = %d\n", rst, rst->data);
} else {
printf("Can not found num 6 \n");
}
rst = searchListNode(ghead, 119);
if(NULL != rst){
printf("node: %p, data = %d\n", rst, rst->data);
} else {
printf("Can not found num 119 \n");
}
}
代码编译
gcc listMain.c list.c -o a.exe -DDEBUG
调试输出
========= Dump List 0x1de6010 ===========
22 32 19 53 0 47 29 116 4 6
===================================
List length = 10
node: 0x1de6130, data = 6
Can not found num 119