数组、链表
数组后移:
int count = j-i;
int temp = array[i];
array[i] = array[j];
while(count>1){
array[i+count] = array[i+count-1];//数组后移
count--;
}
array[i+1] = temp;
1、将i的值放在temp中、将j的值放在i中
2、在count>=2时,每次后移一位
3、将temp的值后移一位
链表
while( head != null){
next = head.next; // 记录当前节点的下一个节点位置;
head.next = pre; // 让当前节点指向前一个节点位置,完成反转
pre = head; // pre 往右走
head = next;// 当前节点往右继续走
}
https://www.cnblogs.com/bjh1117/p/8335108.html