import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
int n = 5;
List<Integer> sourceList = new ArrayList<>(16);
List<Integer> destList = new ArrayList<>(16);
for (int i = 1; i <= n; i++) {
sourceList.add(i);
}
output(sourceList, destList);
for (Integer num : destList) {
System.out.println(num);
}
}
/**
* 递归
*
* @param sourceList
* @param destList
*/
public static void output(List<Integer> sourceList, List<Integer> destList) {
//1.将第一个数加入到目标list,将原list 第一个数去除
//2.将新list第1个数去除,并加入到新list末尾
//3.递归
if (sourceList.isEmpty()){
return;
}
for ( int i = 0; i < 2 ;i++){
if (0==i){
destList.add(sourceList.get(0));
sourceList.remove(0);
}else {
if (!sourceList.isEmpty()){
int temp = sourceList.get(0);
sourceList.remove(0);
sourceList.add(temp);
}
}
}
output(sourceList,destList);
}
}