JAva移動ノードは,集合内のデータソート番号を再ソートし,ztree増削除改査操作を閉パケット形式で実現し,ソートはこの方法を用いる.

2721 ワード

package com.avic.common.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo {
	public static void main(String[] args) {
		Map maps = new HashMap();
		maps.put(1, "a");
		maps.put(2, "b");
		maps.put(3, "c");
		maps.put(4, "d");
		maps.put(5, "e");
		mapsMoveChangeOrderNum(1, 5, maps);
		System.out.println("-------------------------------");
		List lists=new ArrayList();
		lists.add("1");
		lists.add("2");
		lists.add("3");
		lists.add("4");
		lists.add("5");
		listMoveChangeOrderNum(1, 5, lists);
	}
 
	/**
	 *     ,         ,             (  :maps              )
	 * 
	 * @param nowNum
	 *                   
	 * @param moveNum
	 *                  
	 * @param maps
	 *                
	 */
	public static void mapsMoveChangeOrderNum(int nowNum, int moveNum, Map maps) {
		int num = nowNum - moveNum;
		if (num == 0)
			return;
		if (num > 0) {//   ———>      
			for (int i = moveNum - 1; i < nowNum; i++) {
				if (nowNum == i + 1) {
					continue;
				}
				System.out.println(maps.get(i + 1) + "--->" + (i + 2));//        
			}
		} else {
			num = Math.abs(num);//    ———>      
			for (int i = nowNum; i < moveNum; i++) {
				System.out.println(maps.get(i + 1) + "--->" + (i));//        
			}
		}
		System.out.println(maps.get(nowNum) + "--->" + (moveNum));//       
	}
	/**
	 *     ,         ,             (  :lists              )
	 * 
	 * @param nowNum
	 *                   
	 * @param moveNum
	 *                  
	 * @param maps
	 *                
	 */
	public static void listMoveChangeOrderNum(int nowNum, int moveNum, List lists) {
		int num = nowNum - moveNum;
		if (num == 0)
			return;
		if (num > 0) {//   ———>      
			for (int i = moveNum - 1; i < nowNum; i++) {
				if (nowNum == i + 1) {
					continue;
				}
				System.out.println(lists.get(i) + "--->" + (i + 2));//        
			}
		} else {
			num = Math.abs(num);//    ———>      
			for (int i = nowNum; i < moveNum; i++) {
				System.out.println(lists.get(i) + "--->" + (i));//        
			}
		}
		System.out.println(lists.get(nowNum-1) + "--->" + (moveNum));//       
	}
}

実行結果:
b--->1
c--->2
d--->3
e--->4
a--->5
-------------------------------
2--->1
3--->2
4--->3
5--->4
1--->5

インスタンスのソースコードを参照してください.https://download.csdn.net/download/semial/10137674