Indian Institute of Information Technology Sonepat: Dr. Mukesh Mann
Indian Institute of Information Technology Sonepat: Dr. Mukesh Mann
TECHNOLOGY SONEPAT
Submitted To – Submitted By –
Dr. Mukesh Mann Tanishq Verma
Roll No: 12112001
Branch: IT
AIM:
Write Algorithm and program to implement following –
1. Insert a node in front of already created singly link
list
2. Insert a node at the end of already created singly link
list.
3. Insert a node at user speci ed data in already created
singly link list.
ALGORITHM:
1. Algorithm is as follows:
• First, we create a new pointer ‘ptr’ of the struct
node type.
node is to be inserted.
• Link ptr to node having index index.
➢Code: -
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
newnode->next = NULL;
temp = newnode;
}
return head;
}
struct node *insertatbegin(struct node *head) // Inserting At The Beginning {
return head;
}
struct node *insertatlast(struct node *head) {
return head;
}
for (int i = 0; i < index - 1; i++)
{
temp = temp->next;
}
p->next = temp->next;
temp->next = p;
return head;
}
int main() {
int n;
printf("Enter the size of linked list : "); scanf("%d", &n);
// Creating linked list
struct node *head;
head = create_list(n);
// Calling function to insert new node
int index;
printf("Enter the index at which you want to insert node : "); scanf("%d",
&index);
head = insertatgivenindex(head, index);
// To Print The Linked List
struct node *ptr;
ptr = head;
printf("The value in the linked list are: \n");
while (ptr != NULL)