-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrayll.c
46 lines (42 loc) · 884 Bytes
/
arrayll.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//Displaying the elements of linked list using recursion | Vishruth codes
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
}*root=NULL;
void create(int ar[], int n)
{
struct node *last,*temp;
root=(struct node*)malloc(sizeof(struct node));
root->data=ar[0];
root->next=0;
last=root;
for(int i=1;i<n;i++)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->data=ar[i];
temp->next=NULL;
last->next=temp;
last=temp;
}
}
void display(struct node *p)
{
if(p!=NULL)
{
printf("%d -> ",p->data);
display(p->next);
}
}
int main()
{
int len=5;
int ar[]={1,2,3,4,5};
printf("\nThe array: 1,2,3,4,5.");
create(ar,len);
printf("\nThe linked list: ");
display(root);
return 0;
}