题目(2016亚信实习生笔试题):
将链表后半部分反转,编写功能函数。函数头类似于本代码中reList()。
只记得一个大概了,具体规则在代码注释中提到了。
#define NULL 0
#include <stdio.h>
typedef struct LNode
{
char value;
struct LNode *next;
}LNode;
int initLi(LNode **head)//头插法
{
LNode *th=*head;
char c=getchar();
while(c!='$')
{
if(c!=' ')
{
LNode *temp=malloc(sizeof(LNode));
if(temp)
{
temp->value=c;
temp->next=th;
th=temp;
}
else
{
free(temp);
return -1;
}
}
c=getchar();
}
*head=th;
return 0;
}
void visit(LNode **head)
{
LNode *th=*head;
for(LNode *p=th;p!=NULL;p=p->next)
{
printf("%c->",p->value);