出一小题,递归 单链表的逆置
RT.
程序代码:extern "C"
{
#include<stdio.h>
#include<malloc.h>
typedef struct node{
int key;
struct node * next;
}node;
void insert(node *head, int k)
{
node *p=head;
while(p->next)
{
p=p->next;
}
node *q= (node *)malloc(sizeof(node));
q->key=k;
q->next=NULL;
p->next=q;
}
void destroy(node *head)
{
node *p=head;
while(p)
{
head=p;
p=p->next;
free(head);
}
}
void display(node *head)
{
node * p =head;
while(p)
{
printf("%d ",p->key);
p=p->next;
}
printf("\n");
}
node * reverse(node *head)
{
// Your code here
}
int main()
{
node *head=(node *)malloc(sizeof(node));
head->next=NULL;
head->key=0;
int i=1;
for(;i<10;i++)
{
insert(head,i);
}
display(head);
head=reverse(head);
display(head);
destroy(head);
return 0;
}
}









不懂 这到底是做什么用的啊??
