forked from ShreeyansB/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.c
49 lines (44 loc) · 872 Bytes
/
Node.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
47
48
49
#include<stdio.h>
#include<stdlib.h>
struct node {
int data;
struct node *next;
} *first = NULL;
void create(int a[], int size) {
struct node *temp, *last;
int i;
first = (struct node*) malloc(sizeof(struct node));
first->data = a[0];
first->next = NULL;
last = first;
for (i = 1; i < size; i++) {
temp = (struct node*) malloc(sizeof(struct node));
temp->data = a[i];
temp->next = NULL;
last->next = temp;
last = temp;
}
}
void print_list(struct node *p) {
int pos = 0;
while (p) {
printf("%d, ", p->data);
p=p->next;
}
}
void setup_list() {
int i, size;
printf("\nEnter size of Array: ");
scanf("%d", &size);
int arr[size];
printf("\nEnter %d elements:", size);
for (i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}
create(arr, size);
}
void main() {
int arr[] = {4, 5, 6, 7, 9};
create(arr, 5);
print_list(first);
}