# 链表的拆分(线性表)

1 3 5 17 19 23

2 4 14

``````9
12 3 6 7 16 22 27 45 57``````

``````3 7 27 45 57
6 12 16 22 ``````

``````#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
int data;
struct node *next;
}List;

List *Create(int n)
{
int i;

for(i = 0; i < n; i++)
{
p1 = (List *)malloc(sizeof(List));
scanf("%d", &p1->data);

p1->next = p->next;
p->next = p1;
p = p1;
}

}

void Sort(List *p, int n)
{
List *p1, *p2;
int i, j;
int tmp;

p2 = p1 = p;

for(i = 0; i < n; i++)
{
for(j = 0, p1 = p->next; j < n-i-1; j++)
{
if(p1->data > p1->next->data)
{
tmp = p1->data;
p1->data = p1->next->data;
p1->next->data = tmp;
}
p1 = p1->next;
}
}

}

int main()
{
List *head, *p, *p1, *p2, *q1, *q2;
int n;
int i, j;

scanf("%d", &n);

i = j = 0;

Sort(p, n);

while(p->next)
{
p = p->next;
if(p->data % 2)
{
j++;
if( j == 1 )
{
q1 = p1 = p;
}
else
{
p1->next = p;
p1 = p;
}
}
else
{
i++;
if(i == 1)
{
q2 = p2 = p;
}
else
{
p2->next = p;
p2 = p;
}
}
}
p2->next = NULL;
p1->next = NULL;
while(q1)
{
printf("%d ", q1->data);
q1 = q1->next;
}
printf("\n");

while(q2)
{
printf("%d ", q2->data);
q2 = q2->next;
}
printf("\n");

return 0;
}``````

``````#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
int data;
struct node *next;
}List;

List *Create(int n)
{
int i;

for(i = 0; i < n; i++)
{
p1 = (List *)malloc(sizeof(List));
scanf("%d", &p1->data);

p1->next = p->next;
p->next = p1;
p = p1;
}

}

void Sort(List *p, int n)
{
List *p1, *p2;
int i, j;
int tmp;

p2 = p1 = p;

for(i = 0; i < n; i++)
{
for(j = 0, p1 = p->next; j < n-i-1; j++)
{
if(p1->data > p1->next->data)
{
tmp = p1->data;
p1->data = p1->next->data;
p1->next->data = tmp;
}
p1 = p1->next;
}
}

}

int main()
{
List *head, *p, *p1, *p2, *q1, *q2;
int n;
int i, j;

scanf("%d", &n);

i = j = 0;

Sort(p, n);

while(p->next)
{
p = p->next;
if(p->data % 2)
{
j++;
if( j == 1 )
{
q1 = p1 = p;
}
else
{
p1->next = p;
p1 = p;
}
}
else
{
i++;
if(i == 1)
{
q2 = p2 = p;
}
else
{
p2->next = p;
p2 = p;
}
}
}
p2->next = NULL;
p1->next = NULL;
while(q1)
{
printf("%d ", q1->data);
q1 = q1->next;
}
printf("\n");

while(q2)
{
printf("%d ", q2->data);
q2 = q2->next;
}
printf("\n");

return 0;
}``````