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

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

3 Answers   Wipro,


what is electronic software

1 Answers  


method overloading means what?

2 Answers   CTS,


What is C++ could you enplane me please?

1 Answers  


what is an algorithm in terms of STL?

1 Answers   Lucent, Wipro,






How stl is different from the c++ standard library?

0 Answers  


Give the output of the following program main() {int ret; ret=fork();ret=fork();ret=fork();ret=fork(); if(!ret) printf("sun"); else printf("solaris");

8 Answers   Sun Microsystems,


I am doing my BS.c MATHS CAN I ABLE TO JOIN IN NIIT?

2 Answers  


How can you create a bulleted list, numbered list and an outline by using bullets and numbering command. Explain with the help of example.

0 Answers  


what is the difference between thread and process

1 Answers   Infosys,


What is a standard template library (stl)?

0 Answers  


Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister

0 Answers  


Categories