一.链表倒转:
using namespace std;
typedef struct tagNode {
int data;
struct tagNode *next;
} Node;
typedef Node* List;
List reverse(List l)
{
if (l ==
NULL)
exit(0);
if
(l->next == NULL)
exit(0);
Node *p =
l->next; // 从头结点的下一个结点开始。
Node *q =
p->next;
Node *r =
NULL;
while (q)
{
r = q->next;
q ->next = p;
p = q;
q = r;
}
l->next->next = NULL;
l->next = p;
return
l;
}