Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for my algorithm i am using linked list what is best approach for swapping values of unordered nodes of linked is why ...
swapping with pointers itself
Python
nextpointer=current.getNext()              #storing next pointer of of current node
sortednext=sortedCurrent.getNext()         #storing next of sorted current node
sortedLastCurrent.setNext(current)      #set current to next of sorted last current node
current.setNext(sortednext)                #set next of current to sorted next
currentpre.setNext(sortedCurrent)          #set next of currentpre to sorted current sortedCurrent.setNext(nextpointer)         #set next of sorted current to next pointer
sortedCurrent=current                      #set sorted current to current pointer


swapping pointers values
Python
temp=node.getData()
node.setData(node2.getData())
node2.setData(temp)

give me reason which approach is best for heavy(large size of node) nodes swapping
Posted
Updated 14-Dec-14 7:40am
v2

1 solution

"Best" by what measure?
I assume best by execution time and/or memory footprint, correct?
If so:
- Estimate the number of bytes reserved in temporal variables (footprint)?
- Estimate how many bytes have to be copied with each approach (speed)?

For even small data, the answer is clear which is better with the above given criterion.

I leave these estimations as exercise.

Cheers
Andi
 
Share this answer
 
Comments
[no name] 15-Dec-14 5:48am    
best by execution time ...
Andreas Gieriet 15-Dec-14 11:57am    
And the answer is...?
Why?
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900