简体   繁体   English

如何在java中实现类似于set::swap的功能?

[英]How to implement similar to set::swap function in java?

I read the documentation of the C++ set::swap function here and it says that it swaps the content of the sets in constant time .我在这里阅读了 C++ set::swap 函数的文档,它说它以恒定时间交换集合的内容。 I need similar functionality in Java,我需要 Java 中的类似功能,

In java, item access in the set is constant time but I couldn't find a similar function that could swap the content of the sets in constant time and also preserves the variable references.在java中,集合中的项目访问是恒定时间,但我找不到可以在恒定时间内交换集合内容并保留变量引用的类似函数。

I was trying to implement this algorithm in Java.我试图在 Java 中实现这个算法。 What could I use from Java which is similar to this swap function in the referred code?我可以从 Java 中使用什么类似于引用代码中的此交换函数?

I am also fine with manual implementation.我对手动实施也很好。

Thanks,谢谢,

基本上你只想交换每个设置对象内容的指针,我不认为java允许交换引用,因为一旦你设置它就不能改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM