Server : Apache System : Linux profile 3.10.0-1160.88.1.el7.x86_64 #1 SMP Tue Mar 7 15:41:52 UTC 2023 x86_64 User : apache ( 48) PHP Version : 8.0.28 Disable Function : NONE Directory : /var/www/html/venkat/old/ |
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node * next;
};
struct node *new_node()
{
struct node *p;
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&(p->data));
p->next=NULL;
return p;
};
void delete(struct node *head,struct node *pt)
{
struct node *start, *p, *temp;
start=head;
p=pt;
temp=start;
while(temp->next!=p)
temp=temp->next;
temp->next=p->next;
p->next=NULL;
}
int main(void)
{
int n,i;
scanf("%d",&n);
struct node *start, *p;
p=(struct node *)malloc(sizeof(struct node));
start=(struct node *)malloc(sizeof(struct node));
start=p;
p->next=NULL;
scanf("%d",&(p->data));
for(i=1;i<n;i++)
{
p->next=new_node();
}
p=start;
printf("%d",p->data);
while((p->next)!=NULL)
{
p=p->next;
printf("-%d",(p->data));
}
printf("\n");
p=start;
while(p!=NULL)
{
if(((p->data)%2)!=0) delete(start,p);
p=p->next;
}
p=start;
printf("%d",p->data);
while((p->next)!=NULL)
{
p=p->next;
printf("-%d",(p->data));
}
printf("\n");
return 0;
}