 Search:

Submit Article

# Program to create a singly linked list of numbers using threads

Posted By: Easy Tutor     Category: C Programming     Views: 5748

### Write a program to create a singly linked list of numbers using threads. ## Code for Program to create a singly linked list of numbers using threads in C Programming

```# include <stdio.h>

struct parastruct
{
int from;
int to;
}*para;

struct node
{
int no;
struct node *next;
};

int main()
{
int iNumber;
int iCount;
printf("Enter Number up to Which you want to Create List :");
scanf("%d",&iNumber);

if(iNumber<=1)
{
printf("\nError : Enter Number Greater than 1 \n\n");
}
else
{
para=(struct parastruct*)malloc(sizeof(struct parastruct));
para->from=(iNumber/2) + 1;
para->to=iNumber;

for(iCount=1;iCount<=iNumber/2;iCount++)
{
if(iCount==1)
{
list1=(struct node*)malloc(sizeof(struct node));
}
else
{
list1->next=(struct node*)malloc(sizeof(struct node));
list1=list1->next;
}
list1->no=iCount;
list1->next=NULL;
}

list1->next=(struct node*)malloc(sizeof(struct node));
list1->next=list2;

for(iCount=1;iCount<=iNumber;iCount++)
{
if(iCount==para->from)
{
printf("%d \t",list1->no);
list1=list1->next;
}
}
printf("\n");
return 0;
}

{
struct parastruct *paralist;
struct node *list2;
int iCount;
paralist = (struct parastruct*) para;
for(iCount=paralist->from;iCount<=paralist->to;iCount++)
{
if(iCount==paralist->from)
{
list2=(struct node *)malloc(sizeof(struct node));
}
else
{
list2->next=(struct node *)malloc(sizeof(struct node));
list2=list2->next;
}
list2->no=iCount;
list2->next=NULL;
} 