0% found this document useful (0 votes)
5 views1 page

Dsa 6

The document provides a practical implementation of singly linked lists in C, including functions to insert nodes at the beginning and end, delete the first node, and display the list. The main function demonstrates these operations by creating a linked list, displaying it, deleting a node, and displaying the modified list. The output shows the linked list before and after the deletion operation.

Uploaded by

rautrameshwar78
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Dsa 6

The document provides a practical implementation of singly linked lists in C, including functions to insert nodes at the beginning and end, delete the first node, and display the list. The main function demonstrates these operations by creating a linked list, displaying it, deleting a node, and displaying the modified list. The output shows the linked list before and after the deletion operation.

Uploaded by

rautrameshwar78
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Practical 6: Implementation of Linked Lists (Singly,

Doubly, Circular)
Singly Linked List Code:
#include <stdio.h>
#include <stdlib.h>

struct node {
int data;
struct node* next;
};
struct node* head = NULL;

void insertBegin(int data) {


struct node* n = (struct node*)malloc(sizeof(struct node));
n->data = data;
n->next = head;
head = n;
}

void insertEnd(int data) {


struct node* n = (struct node*)malloc(sizeof(struct node));
n->data = data;
n->next = NULL;
if (head == NULL) head = n;
else {
struct node* temp = head;
while (temp->next != NULL) temp = temp->next;
temp->next = n;
}
}

void deleteBegin() {
if (head != NULL) head = head->next;
}

void display() {
struct node* temp = head;
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}

int main() {
insertBegin(10);
insertEnd(20);
insertEnd(30);
printf("Linked List: "); display();
deleteBegin();
printf("After deletion: "); display();
}
Output:
Linked List: 10 -> 20 -> 30 -> NULL
After deletion: 20 -> 30 -> NULL

You might also like