⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sll_remv.c

📁 与C语言四书五经之《C和指针》的配套的书上源代码。
💻 C
字号:
/*
** Remove a specified node from a singly linked list.  The first
** argument points to the root pointer for the list, and the second
** points to the node to be removed. TRUE is returned if it can be
** removed, otherwise FALSE is returned.
*/

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "singly_linked_list_node.h"

#define	FALSE	0
#define TRUE	1

int
sll_remove( struct NODE **linkp, struct NODE *delete )
{
	register Node	*current;

	assert( delete != NULL );

	/*
	** Look for the indicated node.
	*/
	while( ( current = *linkp ) != NULL && current != delete )
		linkp = &current->link;

	if( current == delete ){
		*linkp = current->link;
		free( current );
		return TRUE;
	}
	else 
		return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -