Single Linked List (Inserting a Node at a Certain Position)

preview_player
Показать описание
Data Structures: Inserting a Node at a certain position in a Singly Linked List
Topics discussed:
1) Adding a node in a Singly Linked List to a certain position.
2) C program for inserting a node at a certain position in case of the Singly Linked List.

Music:
Axol x Alex Skrindo - You [NCS Release]

#DataStructuresByNeso #DataStructures #LinkedList #SingleLinkedList
Рекомендации по теме
Комментарии
Автор

This is the best site to learn Data Structures. I've been searching many online sites to get this topic clear But I couldn't find any. But this is the best site to learn. Thank you Sir you are explaining in a very understandable way.

bbennyjoseph
Автор

I have been struggling so much for the past few hours understanding this topic....n u explained it so you so much

binduaradhya
Автор

Thank you so much for making your videos. My C program professor did a terrible job teaching this concept and I paid for the class. I understand it so much more with your videos so thank you.

steventalik
Автор

if you get confused in the while loop then can follow these steps

pos - - ;
while(i < pos)
{ ptr = ptr-> next ;
i++ ;
}

// initialize i at beginning where i = 1

miss_queen-yfbv
Автор

Now it's time solve Gate previous year questions. ....

kajalmondal
Автор

Thanku. Sir, U r god for me, who has made my concept so clear...

RaviShankar-owpu
Автор

I have been attending my DSA lectures for the past two weeks with a blank mind. However, after watching your videos, this topic seems much easier and more interesting. Performing different operations on it now feels achievable. You nailed it bro!

Nen
Автор

this DS course is simply ingenious ... admirations

vasilvasilev
Автор

Thank you so much sir! You have good teaching skill !

You deserved for likes and subscribes!

punky
Автор

at 6:11, In second node the link part should contain address 4000. Otherwise very nice explanation.

hiteshmahi
Автор

This video helped me a lot, Thank you very much!

muaazulhassan
Автор

Great job and i am expecting from you complete data structure Series like Trees Stack Queue
U R the Great Explainer 👍👍👍

muhammadshahab
Автор

Thank u sir, you explained this topic very easily👏

mayuritare
Автор

Is it possible to calculate the insert position in the main function itself, and pass ptr as the reference node while not having to pass the additional positional parameter to the insert function?

anishgupta
Автор

Below is the Universal Code that works for all the positions including the position=1. We need to give separate condition for 1st position.

#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *link;
};

struct node *add_at_end(struct node *ptr, int data){
struct node *temp= malloc(sizeof(struct node));
temp->data = data;
temp->link = NULL;
ptr->link = temp;
return temp;
}
void add_at_pos(struct node **head, int data, int pos){
struct node *ptr = *head;
struct node *ptr2 = malloc (sizeof(struct node));
ptr2->data = data;
ptr2->link = NULL;
if(pos==1)
{
ptr2->link=ptr;
*head=ptr2;
}
else {
pos--;
while(pos != 1){
ptr = ptr->link;
pos--;
}
ptr2->link = ptr->link;
ptr->link = ptr2;
}
}
int main()
{
struct node *head = malloc(sizeof(struct node));
head->data = 45;
head->link = NULL;
struct node *ptr = head;
ptr= add_at_end(ptr, 98);
ptr= add_at_end(ptr, 3);
ptr= add_at_end(ptr, 88);
ptr = head;
int data = 76, position =1
;
add_at_pos(&head, data, position);
struct node *ptr1 = head;
while(ptr1 != NULL){
printf("%d ", ptr1->data);
ptr1=ptr1->link;
}
return 0;
}

nikitamittal
Автор

This is fantastic video your video solve my doubt thank you

gamingharsh
Автор

Sir what if the pos is 1.. that means we need to insert at beginning of the ll?

srikantabanerjee
Автор

Thank you very much, you helped me a lot!

draganjelic
Автор

thank you for the explanation. Can I ask if I want it to be in second position the while loop condition should be while( pos != 0) ?

alikoohi
Автор

Sir, very eager for upcoming videos on data structure.

saketkumar