Linked List Operation in C
Linked List Operation in C
Linked List Operation in C
Experiment No. : 03
Experiment Name: Implementation of Linked List Operations in C
Course Code : CSE135
Course Tittle : Data Structure Lab
Semester : Fall-2023
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
struct node *next;
}Node;
while(temp->next != NULL){
temp = temp->next;
}
temp->next = lastNode;
}
void insertAtMid(Node* head, int data) {
int position;
printf("Enter the position: ");
scanf("%d", &position);
if (position <= 0) {
printf("Error: Invalid position!\n");
return;
}
if (position == 1) {
newNode->next = head->next;
head->next = newNode;
return;
}
Node* current = head;
int currentPosition = 1;
first->data = 1;
first->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = NULL;
head = first;
printer(head);
insertAtEnd(head,4);
printer(head);
head=InsertAtBegin(head,0);
printer(head);
int data;
printf("To insert an element in middle:\n");
printf("Enter the data:");
scanf("%d", &data);
insertAtMid(head,data);
printer(head);
return 0;
}
Output:
Discussion:
------------------------------------End-------------------------------