链表删除结点

//============================================================================
// Name        : ����ɾ����.cpp
// Author      : Lucas
// Version     :
// Copyright   : @Lucas
// Description : 1.是不是头结点。 2.不是头结点,用临时节点存放要被删除的结点,后面的覆盖要被删除的节点,最后删除结点。
//============================================================================

#include <iostream>
using namespace std;

struct node
{
	int data;
	node *next;
};

void deleteNode(node **head, int value)
{
	if (head == NULL || *head == NULL)
	{
		return;
	}

	node *tmpHead = *head;
	while ((tmpHead)->data != value && (tmpHead->next != NULL))
	{
		tmpHead = tmpHead->next;
	}

	if (tmpHead->data != value)
	{
		return;
	}

	if (tmpHead == *head)
	{
		*head = tmpHead->next;
		delete tmpHead;
	}

	node *nodeToBeDelete = NULL;
	tmpHead = tmpHead->next;
	delete nodeToBeDelete;
}

int main() {
	return 0;
}
posted @ 2013-04-28 09:40  helloweworld  阅读(206)  评论(0编辑  收藏  举报