提交 305e9fb7 编写于 作者: cosmicing's avatar cosmicing

Add new file

上级 c1c61ec1
#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
int data;
struct Node *next;
}* LinkList,LinkNode;
void Init(LinkList *L)
{
int i;
*L=(LinkList)malloc(sizeof(struct Node));printf("asddddddddddd\n");
(*L)->next=NULL;
LinkList p=*L;
for(i=0;i<10;i++)
{
LinkList s=(LinkList)malloc(sizeof(struct Node));
s->data=i+1;
s->next=p->next;
p->next=s;
p=s;
}
}
void Print(LinkList L)
{
int i;
LinkList p=L->next;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
int swap(LinkList *L,int i,int j)
{
if(i<=0||j<=0)
{
printf("");
return 0;
}
LinkList p0,p1,q0,q1;
p0=(*L);
p1=(*L);
q0=(*L);
q1=(*L);
while(p1&&i)
{
p0=p1;
p1=p1->next;
//printf("tiaoshi %d ",p1->data);
i--;
}
if(p1&&i!=0)
{
printf("p1-error\n");
return 0;
}
while(q1&&j)
{
q0=q1;
q1=q1->next;
j--;
}
if(q1&&j!=0)
{
printf("q-error\n");
return 0;
}
p0->next=p1->next;
q0->next=q1->next;
q1->next=p0->next;
p0->next=q1;
p1->next=q0->next;
q0->next=p1;
}
int main()
{
LinkList head;
Init(&head);
Print(head);
swap(&head,11,5);
Print(head);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册