-
Notifications
You must be signed in to change notification settings - Fork 91
/
DSAquestions.c
51 lines (37 loc) · 911 Bytes
/
DSAquestions.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
50
51
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int value;
struct node *next;
} node;
int main()
{
int length, i;
printf("Enter size of the list : ");
scanf("%d", &length);
struct node *headNode, *currentNode, *temp;
for (i = 0; i < length; i++)
{
currentNode = (node *)malloc(sizeof(node));
printf("Enter element %d : ", (i + 1));
scanf("%d", ¤tNode->value);
if (i == 0)
{
headNode = temp = currentNode;
}
else
{
temp->next = currentNode;
temp = currentNode;
}
}
temp->next = NULL;
temp = headNode;
printf("Iterating through the elements of the linked list : \n");
while (temp != NULL)
{
printf("%d \n", temp->value);
temp = temp->next;
}
}