#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
void PrintList(struct node *L)
{
struct node *p=L;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
struct node *CreateList();
struct node *DeleteList(struct node *head,int x);
struct node *GetOdd(struct node **L);
struct node *InsertList(struct node *head,struct node *new_node);
int main()
{
struct node *L;
L=CreateList();
PrintList(L);
int m;
scanf("%d",&m);
L=DeleteList(L,m);
PrintList(L);
L=GetOdd(&L);
PrintList(L);
struct node *new_node=(struct node*)malloc((sizeof(struct node)));;
scanf("%d",&new_node->data);
L=InsertList(L,new_node);
PrintList(L);
return 0;
}
struct node *CreateList()
{
int data;
struct node *head=NULL;
struct node *q;
while(scanf("%d",&data)&&data!=-1)
{
struct node *p=(struct node*)malloc((sizeof(struct node)));
if(p!=NULL)
{
p->data=data;
p->next=NULL;
}
else exit(1);
if(head==NULL)
{
head=p;
}
else q->next=p;
q=p;
}
return head;
}
struct node *DeleteHead(struct node *head)
{
struct node *p=head;
head=head->next;
delete p;
p=NULL;
return head;
}
struct node *DeleteList(struct node *head,int x)
{
struct node *pre,*p;
while(head!=NULL&&head->data==x)
{
head=DeleteHead(head);
}
if(head!=NULL)
{
pre=head;
p=head->next;
while(p!=NULL)
{
while(p!=NULL&&p->data==x)
{
pre->next=p->next;
delete p;
p=NULL;
p=pre->next;
}
if(p==NULL) break;
pre=pre->next;
p=p->next;
}
}
return head;
}
struct node *GetOdd(struct node **L)
{
struct node *head=NULL;
struct node *q;
while((*L)!=NULL)
{
int data=(*L)->data;
struct node *p=(struct node*)malloc(sizeof(struct node));
if(data&1)
{
if(p!=NULL)
{
p->data=data;
p->next=NULL;
}
else exit(1);
if(head==NULL)
{
head=p;
}
else q->next=p;
q=p;
}
*L=(*L)->next;
}
return head;
}
struct node *InsertList(struct node *head,struct node *new_node)
{
struct node *p=NULL;
struct node *q=head;
if(head==NULL)
{
head=new_node;
new_node->next=NULL;
return head;
}
while((q->data)<=(new_node->data)&&(q->next)!=NULL)
{
p=q;
q=q->next;
}
if((new_node->data)<(q->data))
{
if(q==head)
{
head=new_node;
new_node->next=q;
}
else
{
p->next=new_node;
new_node->next=q;
}
}
else
{
q->next=new_node;
new_node->next=NULL;
}
return head;
}