The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+2 votes
87 views

Consider the given Doubly Linked List:

Consider C like language code snippet with respect to doubly linked list given

"p" is pointer to linked list node

p=first->next->next->next->prev;
p->next->next->prev=p;
printf("%d",p->next->next->prev->next->data);

What is the output?Plz explain

asked in DS by Veteran (70.4k points) | 87 views

.....8?
Edit : My approach : 

p=first->next->next->next->prev;  // p holds address for node with data value 9
p->next->next->prev=p;            // data value of node holding 10 changes to 9
printf("%d",p->next->next->prev->next->data); prints value of node hold value 8
I got ans 9 ?
plz give explaination

 

I think 10 will be output...

Why not @ akash.dinkar12

1 Answer

+6 votes
Best answer

Such questions are better done using pointer diagrams . Let us show each step of that as follows :

answered by Veteran (96.7k points)
selected by


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

29,167 questions
36,992 answers
92,225 comments
34,837 users