Doubly Linked List | Data Structures & Algorithms | C++ Placement Course | Lecture 22.6

preview_player
Показать описание
Notes of this Lecture:
Рекомендации по теме
Комментарии
Автор

Your code can be reduced to more less code too ( can be made more small too)
But i have understood the concept from here of doubly linked list and implemented and tried changes
Now i understand doubly linked list
Humans always improve

Thank you for this good teaching
Like the video

mikehenry
Автор

Thank u to the entire team of Apna College....

harshpanwar
Автор

your style of teaching is very friendly ..feel paka aya haa :D

HasanSattarr
Автор

We can use two pointer one for pointing at head and another one for pointing at tail.This will be much better in case you want to add at or delete the last node and also to transverse in the opposite direction for tail-> head.

shazibrahman
Автор

11:00 what if head next is already NULL means linkedList have only one element and we try to delete head element using this code.
i think delete head function get error. customized code:
void deleteAtHead(node* &head){
node* todelete = head;

if(head->next == NULL){
head = NULL;
delete todelete;
return;
}
head = head->next;

head->prev = NULL;

delete todelete;
}

imtiyaznandasaniya
Автор

try this to display doubly link list with this way it will give u better feel of doubly link list.
void display(node* head){
cout<<"NULL<-";
while(head != NULL){
cout<<head->data<<"<->";
head=head->next;
} cout<<"NULL"<<endl;
}

jitengarg
Автор

You can add any number/ data at any position. Code:
#include<iostream>
using namespace std;

class node{
public:
int data;
node* next;
node* previous;

node(int val)
{
data=val;
next=NULL;
previous=NULL;
}

};

void insert_at_head(node* &head, int val)
{
node* n= new node(val);
n->next=head;
if(head!=NULL)
{
head->previous=n;
}
head=n;
}

void insert_at_tail(node* &head, int val)
{
node* n=new node(val);
if(head==NULL)
{
//head=n;
insert_at_head(head, val);
return;
}
node* temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=n;
n->previous=temp;
}

void insert_at_pos(node* &head, int val, int pos)
{
node* n=new node(val);
node* temp=head;
node* po=temp->next;

if(head==NULL || pos==1)
{
insert_at_head(head, val);
return;
}

int count=2;
while(count!=pos)
{
temp=temp->next;
if(temp->next==NULL)
{
insert_at_tail(head, val);
return;
}
po=po->next;
count++;
}

temp->next=n;
n->previous=temp;
n->next=po;
po->previous=n;

}

void display(node* head)
{
node* temp=head;
while(temp!=NULL)
{
cout<<""<<temp->data<<"-> ";
temp=temp->next;
}
cout<<"NULL"<<endl;
}

int main()
{
node* head=NULL;
insert_at_tail(head, 1);
insert_at_tail(head, 2);
insert_at_tail(head, 3);
insert_at_tail(head, 4);
insert_at_tail(head, 6);
insert_at_tail(head, 7);
insert_at_pos(head, 5, 8);
insert_at_pos(head, 8, 7);
display(head);
}

ranabasit
Автор

at 4:00 when head==NULL
which means there is no element present in the linked list then why are we creating a function to insert at head
simply write head=n;

yashagarwal
Автор

Thanks a lot.
what a way to teach. i really appreciate
May God bless yu.

thepodcastsbroker
Автор

Dii !
I wrote same code in gfg practice question but it shows segmentation fault..so what can do for that 😶

madhurajput
Автор

I fell in love with Teacher
Just like Montessori student

arbazgujjar
Автор

your is just LIT. and teaching is of god level

sachinupreti
Автор

Your deleteathead will give error if list only contains a head ie its length is 1, line 61 at 11:00

yashvats
Автор

Thank you been at with this problem you finally solved it love

kevinportillo
Автор

And also the course is excellent but just we want more videos fast about all linear and non linear data structures

yasinshaikh
Автор

I have s small question does your deleteathead function work when there is only one node in the list. Because when there is only node in the list the scenario would be like.
the linked lsist - NULL->head->NULL;
first you are assigning head=head->next; after this the head here becomes NULL.. In the next line when you run
head->prev=NULL; this becomes NULL->prev = NULL (which is not possible) (beacuse in the previous line head became NULL);

I mean i think the syntax should belike this

head = head->next;
if(head!=NULL){
head->prev=NULL
}

indukurisatyasrivarma
Автор

Please upload videos continuosly because teacher of our college is not teach like this... No more practicals he still taught us on turbo c ....
I improved myself only your videos
❤️🔥. Love u guys 👍🏻

AbhishekSingh-eobi
Автор

please provide lecture note along copy of code, for easy to copy or paste in our code editor...

biswaranjanbehera
Автор

Mam, where's the note of this lecture?
Please give it us for better results 😊

HardikMondal-jc
Автор

hey aman bhayia kya aap ethical hacking se related kuch gyan kuch learning de sakte it will help alot Plzz reply

seemasamridhi