# 奇数值结点链表

struct ListNode {
int data;
ListNode *next;
};


### 函数接口定义：

struct ListNode *readlist();
struct ListNode *getodd( struct ListNode **L );


### 裁判测试程序样例：

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

struct ListNode {
int data;
struct ListNode *next;
};

struct ListNode *getodd( struct ListNode **L );
void printlist( struct ListNode *L )
{
struct ListNode *p = L;
while (p) {
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}

int main()
{
struct ListNode *L, *Odd;
Odd = getodd(&L);
printlist(Odd);
printlist(L);

return 0;
}

/* 你的代码将被嵌在这里 */


### 输入样例：

1 2 2 3 4 5 6 7 -1


### 输出样例：

1 3 5 7
2 2 4 6

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

#define N 20

struct ListNode {
int data;
struct ListNode *next;
};

struct ListNode *getodd( struct ListNode **L );
void printlist( struct ListNode *L )
{
struct ListNode *p = L;
while (p) {
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}

int main()
{
struct ListNode *L, *Odd;
Odd = getodd(&L);
printlist(Odd);
printlist(L);

return 0;
}

int i=0,in,n,a[N];
struct ListNode *h,*p,*q;

scanf("%d", &in);
while(in != -1){
a[i]=in;
i++;
scanf("%d", &in);
}
n=i;
/*
for(i=0;i<n;i++)
printf("%d ", a[i]);
printf("\n");
*/
h = (struct ListNode*)malloc(sizeof(struct ListNode));
h->data = a[0];
h->next = NULL;
p=q=h;

i=1;
while(i<n){
q = (struct ListNode*)malloc(sizeof(struct ListNode));
q->data = a[i];
q->next = NULL;
p->next = q;
p=q;
i++;
}
p->next=NULL;

return h;
}

struct ListNode *getodd( struct ListNode **L ){
int a[N],i=0,n;

}

while(p){
if(p->data%2==1){
a[i++]=p->data;
q->next=p->next;
free(p);
p=q->next;
continue;
}
q=p;
p=p->next;
}

n=i;
/*调试用
for(i=0;i<n;i++)
printf("%d ", a[i]);
printf("\n");
*/

/*重新建立奇数值的链表*/

i=1;
while(i<n){
q = (struct ListNode*)malloc(sizeof(struct ListNode));
q->data = a[i];
q->next = NULL;
p->next = q;
p=q;
i++;
}
p->next=NULL;

}