JAVA实现swap
来源:互联网 发布:unity3d ngui 实例 编辑:程序博客网 时间:2024/06/10 15:21
public class Swap {public static void swap(int[] data, int a, int b) {int t = data[a];data[a] = data[b];data[b] = t;}public static void main(String[] args) {int[] data = new int[10];for (int i = 0; i < 10; i++) {data[i] = (int) (Math.random() * 100);System.out.print(" " + data[i]);}System.out.println();for (int i = 0; i < 9; i++) {for (int j = i; j < 10; j++) {if (data[i] > data[j]) {swap(data, i, j);}}}for (int i = 0; i < 10; i++) {System.out.print(" " + data[i]);}System.out.println();}}
利用数组实现,这一点上比c/c++弱爆了
或者使用org.omg.CORBA.*Holder
import org.omg.CORBA.IntHolder;/** * Created by N3verL4nd on 2016/11/21. */public class HelloWorld { public static void swap(IntHolder x, IntHolder y){ int temp = x.value; x.value = y.value; y.value = temp; } public static void main(String[] args) { IntHolder x = new IntHolder(10); IntHolder y = new IntHolder(20); System.out.println("交换前:x = " + x.value + " y = " + y.value); swap(x, y); System.out.println("交换后:x = " + x.value + " y = " + y.value); }}
- JAVA实现swap
- 利用java实现swap
- java中swap()的实现
- java中swap函数的实现分析
- Java中swap()方法的实现
- leetcode Swap Nodes in Pairs java实现
- (转)Java中swap()方法的实现
- Swap Nodes in Pairs Java实现
- java反射机制实现swap函数
- java swap
- Swap.java
- java实现c/c++ swap函数(java反射)
- java中如何实现swap(int a,int b)
- c/c++和java实现swap函数的不同处
- c/c++和java实现swap函数的不同处
- c/c++和java实现swap函数的不同处
- 24. Swap Nodes in Pairs (java实现)
- java中实现swap函数的几种方式
- 看不大懂
- QQ图标在win7中的单个隐藏
- mybatis和ibatis的比较
- J2EE综合--关于权限设计的详细探讨
- 2013,我们并肩前行——项目总结
- JAVA实现swap
- linux块设备驱动学习(一)
- java的Overriding和Overloading
- 一位年轻女董事长的37条忠告
- 手机在于折腾,探索未知世界!
- LR有的JMeter也有之一“参数化”
- *.sct: error: No section matches selector - no section to be FIRST/LAST.
- 基于java的俄罗斯小方块(二),code,code...
- spring IOC annotation