您的位置:首页 > 编程语言 > Java开发

bubble sort in linked list....(java version)

2012-01-28 22:06 281 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: