首页 > 代码库 > 057_删除聊表中的重复的节点

057_删除聊表中的重复的节点

#include <iostream> 
#include <vector>
using namespace std;


typedef struct ListNode {
	int data;
	struct ListNode * next;
	ListNode(int d) : data(d), next(NULL){}
};

ListNode *initList(int *array, unsigned int length) {
	
	if(!array) {
		return NULL;
	}

	ListNode * head = NULL;
	head = new ListNode(array[0]);
	ListNode * p = head;
	head->next = NULL;
	
	unsigned int i = 1;
	for(; i < length; i++) {
		p->next = new ListNode(array[i]);
		p = p->next;		
	}

	
	return head;
	
} 

void printList(ListNode *head) {
	
	ListNode * p = head;
	if (!head){
		return;
	}
	while (p && p->next) {
		cout<<p->data<<"->";
		p = p->next; 
	}
	if (p) {
		cout<<p->data<<endl;
	}
	
}

ListNode *removeDuplicateNode(ListNode *head) {
	if (head == NULL) {
		return NULL;
	}
	ListNode *pre = head;
	ListNode *post = pre->next;
	while(pre != NULL && post != NULL) {
		if (pre->data =http://www.mamicode.com/= post->data) {//delete post node >

057_删除聊表中的重复的节点