Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么我的代码中显示runtime Error

Posted by jiangna20103378 at 2015-04-06 17:59:58 on Problem 2255
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main{
	class Node {
		char data;
		Node leftNode;
		Node rightNode;

		public char getData() {
			return data;
		}

		public void setData(char data) {
			this.data = data;
		}

		public Node getLeftNode() {
			return leftNode;
		}

		public void setLeftNode(Node leftNode) {
			this.leftNode = leftNode;
		}

		public Node getRightNode() {
			return rightNode;
		}

		public void setRightNode(Node rightNode) {
			this.rightNode = rightNode;
		}

	}

	public static Node constructTree(List<Character> pre, List<Character> mid,
			int length) {
		Main mainA2255 = new Main();
		Node node = mainA2255.new Node();
		if (length == 0)
			return null;
		int rootIndex = 0;
		for (int i = 0; i < length; i++) {
			if (mid.get(i) == pre.get(0)) {
				rootIndex = i;
				break;
			}
		}
		node.data = mid.get(rootIndex);
		node.leftNode = constructTree(pre.subList(1, pre.size()), mid,
				rootIndex);

		node.rightNode = constructTree(pre.subList(rootIndex + 1, pre.size()),
				mid.subList(rootIndex + 1, mid.size()), length - rootIndex - 1);

		return node;

	}

	public static void postOrder(Node node) {
		if (node == null)
			return;
		postOrder(node.leftNode);
		postOrder(node.rightNode);
		System.out.print(node.data);
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {

			String string = scanner.nextLine();
			String[] strs = string.split(" ");
			if (strs.length >= 2) {
				char[] pre = strs[0].toCharArray();
				char[] mid = strs[1].toCharArray();
				if (pre.length == mid.length) {
					ArrayList<Character> pre1 = new ArrayList<Character>();
					ArrayList<Character> mid1 = new ArrayList<Character>();
					for (int i = 0; i < pre.length; i++) {
						pre1.add(pre[i]);
						mid1.add(mid[i]);
					}

					postOrder(constructTree(pre1, mid1, pre1.size()));
				}
				
			}

		}
	}

}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator