The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+3 votes
131 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 (96.2k points) | 131 views
0

.....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
0
I got ans 9 ?
0
plz give explaination
+1

I think 10 will be output...

0

Why not @ akash.dinkar12

1 Answer

+7 votes
Best answer

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

answered by Veteran (99.2k 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

39,825 questions
46,802 answers
140,978 comments
58,918 users