Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Linked list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,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", &currentNode->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;
}
}