You are on page 1of 4

#include<stdio.

h>
#include<malloc.h>
#include<time.h>
typedef struct link
{
int data;
struct link *next;
}node;
node *start=NULL;
node *start1=NULL;
node *ptr;
node *ptr1;
int main()
{
int n,i=0,count;
scanf("%d",&n);
srand(time(NULL));
int dec = (rand()%10)+1;
for(i=0;i<n;i++)
{
int is = (rand()%10)+1;
if(i<dec)
{
if(i%2==0)
{
node *temp=(node *)malloc(sizeof(node));
temp->data=is;
temp->next=NULL;
if(start==NULL)
start=temp;
else
{
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=temp;
}

}
else
{
node *temp1=(node *)malloc(sizeof(node));
temp1->data=is;
temp1->next=NULL;
if(start1==NULL)
start1=temp1;
else
{
ptr1=start1;
while(ptr1->next!=NULL)
ptr1=ptr1->next;
ptr1->next=temp1;
}

}
else
{
node *temp2=(node *)malloc(sizeof(node));
temp2->data=is;
temp2->next=NULL;

ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=temp2;

node *temp3=(node *)malloc(sizeof(node));


temp3->data=is;
temp3->next=NULL;
ptr1=start1;
while(ptr1->next!=NULL)
ptr1=ptr1->next;
ptr1->next=temp3;

}
}

ptr=start;
count=0;
int y=(dec%2==0)?(dec/2):(dec/2 +1);
while(ptr!=NULL && count<y)
{
printf("%d ",ptr->data);
count++;
ptr=ptr->next;
}
printf("\n");
ptr1=start1;
count=0;
while(ptr1!=NULL)
{
printf("%d ",ptr1->data);
count++;
if(count==dec/2)
printf("\n");
ptr1=ptr1->next;
}

You might also like