



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This code snippet demonstrates the implementation of a linked list data structure in c. It covers basic operations like insertion, deletion, and display. The code provides a clear and concise example of how to create, manipulate, and traverse a linked list, making it a valuable resource for understanding this fundamental data structure.
Typology: Slides
1 / 6
This page cannot be seen from the preview
Don't miss anything!
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data; struct node *next;
};
void display (struct node* head)
{
struct node *temp = head; printf("\n\nList elements are - \n"); while(temp != NULL) { printf("%d --->",temp->data); temp = temp->next; }
}
void insertAtMiddle (struct node *head, int position, int value) { struct node *temp = head; struct node newNode; newNode = (node)malloc(sizeof(struct node)); newNode->data = value;
int i;
for(i=0; i<position-1&& temp!=NULL;i++) { temp = temp->next; }
newNode->next = temp->next; temp->next = newNode; }
void insertAtFront (struct node** head, int value) {
struct node newNode; newNode = (node)malloc(sizeof(struct node)); newNode->data = value; newNode->next = head; *head = newNode;
}
void deleteFromFront (struct node** headRef){ head=(head)->next; }