java实现合并两个有序单链表

public class MergeLink {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String str1 = scanner.nextLine();
		String str2 = scanner.nextLine();
		NodeList node1 = createNodeList(str1);
		NodeList node2 = createNodeList(str2);
		NodeList newNode = null;
		if(node1 !=null && node2 !=null){
			newNode = mergeLink(node1, node2);
		}
		System.out.println(newNode);
	}
	
	/**
	 * 创建单链表
	 * @param str
	 * @return
	 */
	public static NodeList createNodeList(String str){
		
		if(str ==null || str.length() <=0){
			return null;
		}
		
		char[] s = str.toCharArray();
		NodeList[] nodeLists = new NodeList[s.length];
		//初始化链表
		for(int i=0;i

 

你可能感兴趣的:(算法与数据结构,合并两个有序单链表)