0% found this document useful (0 votes)
3 views2 pages

Linked List Creation from Array in C

The document presents a C program that implements a linked list using an array. It includes functions to create a linked list from array elements and display the linked list. The program prompts the user for the number of elements and their values, then outputs the linked list accordingly.

Uploaded by

Sunith Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Linked List Creation from Array in C

The document presents a C program that implements a linked list using an array. It includes functions to create a linked list from array elements and display the linked list. The program prompts the user for the number of elements and their values, then outputs the linked list accordingly.

Uploaded by

Sunith Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Linked list implementation using array:

#include<stdio.h>
struct node
{
int info;
struct node* next;
};

/*
Function to create Linked List from Array elements.
*/

struct node* createLL(int* nAR, int n)


{
static int i=0;
struct node* temp = NULL;
if(n==0)
return NULL;
// Create New Node
temp = (struct node*)malloc(sizeof(struct node*));
temp->info = nAR[i++];
temp->next = createLL(nAR, --n);
return temp;
}

void displayLL(struct node *temp)


{
while(temp)
{
printf("%d ", temp->info);
temp=temp->next;
}
}
int main()
{
int n=0, i=0, AR[100]={0};
struct node *t = NULL;
printf("\nEnter the number of elements: ");
scanf("%d", &n);
for(i=0; i<n; i++)
scanf("%d", &AR[i]);

printf("\nCreate linked list from array");


t =createLL(AR, n);
printf("\nDisplay Linked List : \n");

if(t)
displayLL(t);
}

OUTPUT|
Enter the number of elements: 5

Create linked list from array


5 6 7 8 9

Display Linked List:


5 6 7 8 9

You might also like