node* addAtPos(node* head, int data, int pos){ node *temp=malloc(sizeof(struct node)); temp->prev=NULL; temp->data=data; temp->next=NULL; if(pos==0){ temp->next=head; head->prev=temp; head=temp; return head; } else{ node *tp=head; int i=0; while(i++!=pos-1) tp=tp->next; temp->next=tp->next; tp->next=temp; temp->prev=tp; return head; } } I did this on my own. works well for all positions.
1 part is about inserting a node after a specific position for which the condition in while loop was (position !=1) and part 2 is about inserting a node after a specific position for which the condition in while loop is (position > (position -1))
Thank you sir for your quick response. Best ds tutorial
This channel as been my all time fav
Short, precise and very Informative! Great content this is 💯💯💯
node* addAtPos(node* head, int data, int pos){
node *temp=malloc(sizeof(struct node));
temp->prev=NULL;
temp->data=data;
temp->next=NULL;
if(pos==0){
temp->next=head;
head->prev=temp;
head=temp;
return head;
}
else{
node *tp=head;
int i=0;
while(i++!=pos-1) tp=tp->next;
temp->next=tp->next;
tp->next=temp;
temp->prev=tp;
return head;
}
}
I did this on my own. works well for all positions.
Sir , last node prev part value is 4000 so plz replace 2000 to 4000 sir....
Thank you so much neso academy. This is helping me alot with my studies 💯 excellent series!!!!💯💯
As usual, AWESOME.....🙏🙏🙏🙏
Sir, why you've put that semicolon after the closing bracket of function???
temp2--> prev = newP so shouldn't 2000 in prev be change to 4000? In the vid it's still 2000 and haven't been changed
Sir please complete this series as soon as possible....
To add new node at the beginning of the list, you have used if clause to update the head, but it won't get reflected in main function.
Why are we doing before and after a specific position instead of like what we did with normal linked list ?
I believe for the sake of breaking down the concept for the students to fully absorb it.
We also can changeIn previous code and every thing same-while(pos != 2)
Thank You for making this presentation sir
best playlist!
I love Neso Academy :)
temp->prev=newp;
temp->prev=4000;
what is the difference on while condition is different in part 1 and 2 is it necessary to change the condition?
Why are we returning head in the addBeforePos function?
We are not changing the value inside the head pointer.
you are best
When this Course will complete fully??
That is temp2 prev part value 4000
In this program position is fixed
Nice.
Sir plzz can you provide us the whole code which you describe
Plzzz Sir
Here is my code with no need of two temp pointer:
void addAtPosition(Node *head, int data, int position)
{
Node *newNode = (Node *)malloc(sizeof(Node));
Node *temp;
temp = head;
if (position == 1)
addAtBeginnning(head);
else
{
while (position > 2)
{
temp = temp->next;
position--;
}
newNode->data = data;
newNode->next = temp->next;
newNode->prev = temp;
temp->next = newNode;
newNode->next->prev = newNode;
}
}
What to change in this code for user input ?
Sir, this code is not printing if we pass pos =1 😟😞.
I cant differentiate between part 1 & 2
1 part is about inserting a node after a specific position for which the condition in while loop was (position !=1) and part 2 is about inserting a node after a specific position for which the condition in while loop is (position > (position -1))
@@aditisamargade1307 thanks! I found out.
@@aditisamargade1307 I am little confused. what is the difference in part 1 and part 2 i can't understand
part 1 is about inserting new node after the given position and part 2 is about inserting new node before the given position.
please give us the source code sir