public void swap(customerNode pre, customerNode cur) {
customer temp = pre.item.clone();
pre.item = cur.item.clone();
cur.item = temp.clone();
}
customerNode bubble(customerNode phead, int len) {
customerNode ptr, next;
int temp;
for (int i = 0; i < len; i++) {
ptr = phead;
next = ptr.next;
for (int j = 0; j < len - i - 1; j++) {
if (ptr.item.getId() > next.item.getId()) {
swap(ptr, next);
}
ptr = ptr.next;
next = next.next;
}
}
return phead;
}bubble sort in linked list....(java version)
最新推荐文章于 2025-12-01 13:49:36 发布
本文介绍了在Java中实现对象交换算法的一种方法,通过复制对象属性来完成元素位置的互换,适用于数组或其他集合结构。
134

被折叠的 条评论
为什么被折叠?



