链表结点的逆置

struct number *invert(struct number *num)
{
	struct number *p1 = num, *p2 = NULL, *p3 = NULL;

	while (p1->next != NULL) {
		p2 = p1;
		p1 = p1->next;
		if (p1 == num)
			p2->next = NULL;
		else
			p2->next = p3;
		p3 = p2;
	}
	p1->next = p2;
	num = p1;

	return num;
}

你可能感兴趣的:(C学习笔记)