燕子的很好。。我一直掉线啊。。。
#include<stdio.h>
#include<malloc.h>
typedef struct node_t
{
int a;
struct node_t *next;
}node_t;
node_t * ChangeTwoNodes(node_t *list)
{
if(list==NULL) return NULL;
if(list->next==NULL) return list;
node_t *pret=list->next,*p, *t;
for (t=list; (list) && (p=list->next); list=list->next)
{
t->next = p;
list->next = p->next;
p->next = t = list;
}
return pret;
}
node_t * makenode(node_t *list,int n,int i)
{
list=(node_t *)malloc(sizeof(node_t ));
list->a=n;
list->next=NULL;
if(n==i)
return list;
else
{
list->next=makenode(list->next,++n, i);
return list;
}
}
int main()
{
node_t *list,*p;
list=makenode(list,1,6);
for(p=list;p;p=p->next)
printf("%d ",p->a);
printf("\n");
p=ChangeTwoNodes(list);
for(;p;p=p->next)
printf("%d ",p->a);
printf("\n");
return 0;
}
#include<stdio.h>
#include<malloc.h>
typedef struct node_t
{
int a;
struct node_t *next;
}node_t;
node_t * ChangeTwoNodes(node_t *list)
{
if(list==NULL) return NULL;
if(list->next==NULL) return list;
node_t *pret=list->next,*p, *t;
for (t=list; (list) && (p=list->next); list=list->next)
{
t->next = p;
list->next = p->next;
p->next = t = list;
}
return pret;
}
node_t * makenode(node_t *list,int n,int i)
{
list=(node_t *)malloc(sizeof(node_t ));
list->a=n;
list->next=NULL;
if(n==i)
return list;
else
{
list->next=makenode(list->next,++n, i);
return list;
}
}
int main()
{
node_t *list,*p;
list=makenode(list,1,6);
for(p=list;p;p=p->next)
printf("%d ",p->a);
printf("\n");
p=ChangeTwoNodes(list);
for(;p;p=p->next)
printf("%d ",p->a);
printf("\n");
return 0;
}
学习需要安静。。海盗要重新来过。。