0% found this document useful (0 votes)
2 views

Singly Linked List Dynamic Implementation C Program

The document contains C code for a simple linked list implementation. It includes functions to create nodes, insert nodes at the beginning of the list, and display the list. The main function initializes an empty list and inserts three elements before displaying the linked list.

Uploaded by

2024293571.navya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Singly Linked List Dynamic Implementation C Program

The document contains C code for a simple linked list implementation. It includes functions to create nodes, insert nodes at the beginning of the list, and display the list. The main function initializes an empty list and inserts three elements before displaying the linked list.

Uploaded by

2024293571.navya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h> // Function to display the linked list


#include <stdlib.h> void display(struct Node* head) {
struct Node* current = head;
// Node structure while (current != NULL) {
struct Node { printf("%d -> ", current->data);
int data; current = current->next;
struct Node* next; }
}; printf("NULL\n");
}
// Function to create a new node
struct Node* createNode(int value) { // Main function
struct Node* newNode = (struct int main() {
Node*)malloc(sizeof(struct Node)); struct Node* head = NULL; // Initialize an empty list
newNode->data = value;
newNode->next = NULL; // Insert elements
return newNode; insert(&head, 10);
} insert(&head, 20);
// Function to insert a node at the beginning insert(&head, 30);
void insert(struct Node** head, int value) {
struct Node* newNode = createNode(value); // Display the linked list
newNode->next = *head; printf("Linked List: ");
*head = newNode; display(head);
} return 0;
}

You might also like