#includestruct a { //结构a的定义
int n;
struct a *next;
} A;
struct a *creat() //建立链表函数
{
int count=1,n;
struct a *p,*tail,*L;
L=tail=NULL;
printf("输入-1结束\n");
while (1)
{
printf("请输入第%d个正整数: ",count);
scanf("%d",&n);
if(nn=n;
p->next=NULL;
if(L==NULL)
L=p;
else
tail->next=p;
tail=p;
count++;
}
}
return L;
}
int main ()
{
struct a *L,*NEW=NULL,*pL,*pNEW,*tail=NULL,*p;
L=creat();
for(pL=L;pL!=NULL;pL=pL->next) //遍历链表L的循环
if(pL->n%2) //筛选出奇数,放入新链表NEW中
{
pNEW=(struct a *)malloc(sizeof(struct a));
pNEW->n = pL->n;
pNEW->next = NULL;
if(NEW==NULL)
NEW = pNEW;
else
tail->next = pNEW;
tail = pNEW;
}
if(NEW==NULL)
{
printf("NEW中不含任何信息!\n");
return 0;
}
printf("NEW链表中的信息为:\n");
for(p=NEW;p!=NULL;p=p->next) //遍历新链表NEW输出NEW中信息
printf("%d ",p->n);
printf("\n");
return 0;
}