Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having a problem with this. It's only printing once, making a comparison between H < i. Help? public static ArrayList organizePrefixOrder(ArrayList a, ArrayList b)

I'm having a problem with this. It's only printing once, making a comparison between H < i. Help? public static ArrayList organizePrefixOrder(ArrayList a, ArrayList b) { int compared; if (a.size() == 0) { b.add(b.size(), a.get(0)); return b; } else { compared = byPrefixOrder().compare(a.get(0), a.get(1)); System.out.println(compared); if (compared > 1) { b.add(0, a.get(1)); a.remove(1); return organizePrefixOrder(a,b); } else if (compared == 1) { b.add(1, a.get(0)); b.add(2, a.get(1)); a.remove(0); a.remove(1); return organizePrefixOrder(a,b); } else { b.add(a.get(0)); a.remove(0); return organizePrefixOrder(a,b); } } } 
public static Comparator byPrefixOrder() { return new ComparatorByPrefixOrder(); } 
private static class ComparatorByPrefixOrder implements Comparator { @Override public int compare(Term a, Term b) { if (a.getSearched().charAt(0) == b.getSearched().charAt(0)) { System.out.println(a.getSearched().charAt(0) + "=" + b.getSearched().charAt(0)); return 0; } else if (a.getSearched().charAt(0) > b.getSearched().charAt(0)) { System.out.println(a.getSearched().charAt(0) + ">" + b.getSearched().charAt(0)); return -1; } else  System.out.println(a.getSearched().charAt(0) + "<" + b.getSearched().charAt(0)); return 1; } } 

Error:

1 How to Get Away with Murder

Exception in thread "main" 2 iZombie

3 Breaking Bad

8 Schussler Sucks More

4 Big Bang Theory

H

1

java.lang.IndexOutOfBoundsException: Index: 1, Size: 0

at java.util.ArrayList.rangeCheckForAdd(ArrayList.java:665)

at java.util.ArrayList.add(ArrayList.java:477)

at Term.organizePrefixOrder(Term.java:77)

at Term.main(Term.java:175)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

Students also viewed these Databases questions