链表操作函数集合(C++)

反转单向链表

void ReverseList(Node* head) {
	//反转带头节点指针的单向链表
	Node* pre = NULL;
	Node* cur = head->next;
	Node* nex = cur->next;
	
	while (cur != NULL) {
		cur->next = pre;
		pre = cur;
		cur = nex;
		nex = (nex == NULL) ? NULL : nex->next; 	
	}
	head->next = pre;

}
上一篇:[转]状态压缩dp(状压dp)


下一篇:[atARC077F]SS