Single Linked List (Deleting the Node at a Particular Position)

preview_player
Показать описание
Data Structures: Deleting the Node of a Singly Linked List at a Specified Position.
Topics discussed:
1) C program to delete the node of a singly linked list present at a particular position.

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

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

This is a blessing to us who are not having any classes to study! Brilliant teaching literally! Also please complete the series, trees graphs and everything

bhavyabhagwani
Автор

Thank you for this. Brilliant as always.

krishnakumarjha
Автор

Neso puts out the highest quality videos I have been able to find on these topics, this is the type of instruction one would expect to find in a college course that you paid too much money for, but in reality it's better than 95% of them. Thank you sir, God bless.

Jeremyak
Автор

logic is understandable but writing code is ....

ahmettunaergul
Автор

alternate solution:

void delete_node_at_position (struct node* head, int position) {

struct node* ptr = head;

for(int i=1; i<position-1; i++){
ptr=ptr->link;
}
ptr->link=ptr->link->link;

free(ptr->link);
ptr=NULL;

cout<<"node deleated Sucessfully at position "<<position<<endl<<endl;

}

anshgupta
Автор

Thankyou very much sir, without you I can't understand programming.

Thannila.G-lb
Автор

Sir, Please upload double linked list, stack, queue as soon as possible 🙏🙏🙏 this will help us to prepare for placement this year

pulastyadas
Автор

Sir, Honestly speaking I have no words that I explain your vast knowledge about Data Structure on YouTube
But unfortunately, I couldn't find a complete series on data structure

khabibali
Автор

Thanks a lot, i was stuck at this topic, now i am completely satisfied, thanks again

PrasunNath
Автор

Pls upload daily & cover whole series of dsa

Ankit-mhqx
Автор

This is the best site to learn Data Structures.

evash
Автор

thank U very much really helped a lot when I had an assignment to submit in 3

Unknwn_Legend
Автор

@neso acedmy
It is very helpful for us...
Please upload the remained topic
..

rahulkumar_
Автор

I didn't understand why we use the double pointer in this fuction, why doesn't it work if we use head like in the other functions?

MortalKombatTS
Автор

hey guys i have followed along the whole series, here is the complete code // Online C compiler to run C program online
#include <stdio.h>
#include <stdlib.h>


struct node {
int data;
struct node *link;
};

int print_datan_count(struct node *head){
int count=0;
if(head==NULL)
printf("Link list is Empty");

struct node *ptr=head;
while(ptr!=NULL){
count++;
printf("%d ", ptr->data);
ptr=ptr->link;
}
printf("\ncount=%d", count);
}

int add_at_end(struct node *head, int data){
struct node *ptr;
ptr=head;
struct node *temp=malloc(sizeof(struct node));
temp->data=data;
temp->link=NULL;

while(ptr->link!=NULL){
ptr=ptr->link;
}
ptr->link=temp;

}

struct node* add_at_beg(struct node *head, int data){
struct node *ptr=malloc(sizeof(struct node));
ptr->data=data;
ptr->link=head;
head=ptr;
return head;
}

void insert_pos(struct node *head, int data, int pos){
struct node *ptr=head;
struct node *temp=malloc(sizeof(struct node));
temp->data=data;
temp->link=NULL;
if(pos==1){
printf("Use add_at_beg function");
exit(0);
}
else{
pos--;
for(int i=1;i<pos;i++){
ptr=ptr->link;
}
temp->link=ptr->link;
ptr->link=temp;
}
}

struct node *del_first(struct node *head){
if(head==NULL){
printf("Linked List is Empty");
}
else{
struct node *temp=head;
head=head->link;
free(temp);
temp=NULL;
}
return head;
}

void *del_last(struct node *head){
if(head==NULL){
printf("Link List is Empty");
}
else if(head->link==NULL){
free(head);
head=NULL;
}
else{
struct node* temp=head;
struct node* ptr=head;
while(temp->link->link != NULL){
temp=temp->link;
}
free(temp->link);
temp->link=NULL;
}
// return head;
}

struct node *del_pos(struct node *head, int pos){
struct node *ptr=head;
struct node *temp=head;
if(head==NULL){
printf("Linked List is Empty");
}
else if(pos==1){
head=ptr->link;
free(ptr);
ptr=NULL;
}
else{
while(pos!=1){
temp=ptr;
ptr=ptr->link;
pos--;
}
temp->link=ptr->link;
free(ptr);
ptr=NULL;
}
}

int main(){
// Write C code here
struct node *head=malloc(sizeof(struct node));
head->data=70;
head->link=NULL;

struct node *current=malloc(sizeof(struct node));
current->data=60;
current->link=NULL;
head->link=current;

current=malloc(sizeof(struct node));
current->data=40;
current->link=NULL;
head->link->link=current;

//count_nodes(head);


add_at_end(head, 64);
head=add_at_beg(head, 45);
insert_pos(head, 444, 6);
head=del_first(head);
del_last(head);
del_pos(head, 4);

//printf("\n");
print_datan_count(head);


return 0;
}

TECH-chdm
Автор

Sir please upload all the videos fastly I am very curious to learn from your videos

yashsinghal
Автор

But we can also achieve this by using only one pointer instead of current and previous !

amankumarsingh
Автор

U r just awesome And your teaching style is best😊

shilpakumari
Автор

Pastly watches 3 videos on it but was still not getting, this one has made it clear

utkarshgupta
Автор

Sir plz upload the remaining portion of the data structures because it is to helpful 🙏🙏🙏🙏🙏

hi-xuee