双向链表的查找 -- C语言

代码实现

st_doubNode* searchDoubListNode(st_doubNode* head, int num){
	if(NULL == head){
		return NULL;
	}

	st_doubNode* p = NULL;
	st_doubNode* q = NULL;

	p = head;
	while(NULL != p){
		if(p->data == num){
			q = p;
			break;
		}

		p = p->next;
	}
	
	return q;
}


void testSearchDoubList(void){
	st_doubNode * rst = NULL;
	rst = searchDoubListNode(gDoubHead, 6);

	printf("\n************  testSearchDoubList ************ \n");
	
	if(NULL != rst){
		printf("node: %p, data = %d\n", rst, rst->data);
	} else {
		printf("Can not found num 6 \n");
	}

	rst = searchDoubListNode(gDoubHead, 119);
	if(NULL != rst){
		printf("node: %p, data = %d\n", rst, rst->data);
	} else {
		printf("Can not found num 119 \n");
	}	
}

调试编译

gcc listMain.c doublist.c  -o a.exe -DDEBUG

调试输出

************  testSearchDoubList ************
node: 0x1e6d130, data = 6
Can not found num 119
发布了191 篇原创文章 · 获赞 43 · 访问量 26万+

猜你喜欢

转载自blog.csdn.net/leoufung/article/details/104374564