how to swap two numbers in a linked list without exchanging
the data but only the links?

Answers were Sorted based on User's Feedback



how to swap two numbers in a linked list without exchanging the data but only the links?..

Answer / sha

let q=20,r=10 and p be a node previous to q
sequence is p-q-r
temp is pointer of link list.
then
temp=p->next;
p->next=temp->next;
p->next->next=temp;
and temp next can be conected to p->next->next->next if
there is any

Is This Answer Correct ?    4 Yes 0 No

how to swap two numbers in a linked list without exchanging the data but only the links?..

Answer / pavny

Suppose List contains 3 no. 10, 20, 30
try to exchange 10 and 20.
head points to 10.

temp = head;
head = head -> next;
temp -> next = head - next;
head -> next = temp;

I think it works..

Is This Answer Correct ?    3 Yes 2 No

how to swap two numbers in a linked list without exchanging the data but only the links?..

Answer / siva

head points 20
head=head->link;
link->next;
link->head=head->next

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More STL Interview Questions

What is 2*2?

7 Answers  


WHAT IS THE DIFFERENCE BETWEEN C++ AND VC++

1 Answers   Syntel,


Define the terms: field, record, table and database

5 Answers  


What is the name of your birth place?

0 Answers  


What Is Operator Overloading in C++?

3 Answers  


why & sign is used in copy constructor

4 Answers  


What are the symptoms of stl?

0 Answers  


how to making game in c++ ?

0 Answers  


Distinguish between: a) Normal layout & Print Layout views b) Windows Clipboard & office Clipboard c) Save & Save As Commands d) Program File & Data File e) Pie Charts & Barr Charts

0 Answers  


what is strcture i++ i ++i answer to this i=5 what is the out put

6 Answers  


what's the difference between function overloading and function overiding?

5 Answers  


give me the defination of inheritance?

5 Answers   Infosys,


Categories