通过交换值或指针本身进行指针排序 [英] pointer sorting by swapping values or by pointer itself

查看:96
本文介绍了通过交换值或指针本身进行指针排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的算法我使用链表是什么是交换链接无序节点值的最佳方法是为什么...

用指针交换本身

 nextpointer = current.getNext() 存储下一个指针当前节点 
sortednext = sortedCurrent.getNext() 存储排序当前节点的下一个
sortedLastCurrent.setNext(当前) 将当前设置为排序的最后一个当前节点的下一个
current.setNext(sortednext) 设置当前下一个排序的下一个
currentpre.setNext(sortedCurrent) 将currentpre的下一个设置为已排序的当前sortedCurrent.setNext (nextpointer)#set next of sorted current to next pointer
sortedCurrent = current set sorted当前指向当前指针





交换指针值

< pre lang =Python> temp = node.getData()
node.setData(node2.getData())
node2.setData(temp)



给我理由哪种方法最适合重(大型节点)节点交换

解决方案

最佳的措施是什么?

我认为执行时间和/或内存占用最好,对吗?

如果是这样的话:

- 估算时态变量(足迹)中保留的字节数?

- 估计每种方法必须复制多少字节(速度)?



对于即使很小的数据,答案也很明确使用上面给出的标准会更好。



我将这些估算作为练习。



干杯

Andi


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

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

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

解决方案

"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


这篇关于通过交换值或指针本身进行指针排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆