Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help to create a binary search that I need to create a AlphaFinder class that implments a third comparator I already post this

I need help to create a binary search that I need to create a AlphaFinder class that implments a third comparator I already post this question twice can some one please help me thank you

2) At the end of main is a comment to search for the string bbbw. Add the appropriate code to perform a binary search for that string and print the location where it was found. You will need to implement a third comparator, AlphaFinder, for this purpose.

Hint: You need to use the substring and charAt methods in the String class.

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Collections;

public class SortRunner

{

public static void main(String[] args) {

ArrayList al = new ArrayList();

al.add("aaa888q");

al.add("aaa888q");

al.add("aaa555q");

al.add("aaa333q");

al.add("aaa888p");

al.add("aaa888a");

al.add("bbb111z");

al.add("bbb222w");

al.add("ccc777a");

al.add("eee888b");

al.add("zzz000c");

al.add("zzz666d");

al.add("ppp333e");

al.add("ppp111f");

ReverseWordSorter rws = new ReverseWordSorter();

Collections.sort(al,rws);

System.out.println("ReverseWord order:");

for(String s : al)

System.out.println(s);

LetterNumberSorter ls = new LetterNumberSorter();

Collections.sort(al,ls);

System.out.println("Letter-Number order:");

for(String s : al)

System.out.println(s);

// NumberLetterSorter nls = new NumberLetterSorter();

// Collections.sort(al,nls);

// System.out.println("Number-Letter order:");

// for(String s : al)

// System.out.println(s);

// Add code to search for the string "bbbw".

}

}

import java.util.Comparator;

public class ReverseWordSorter implements Comparator

{

public int compare(String a, String b)

{

return -1 * (a.compareTo(b)) ;

}

}

import java.util.Comparator; public class LetterNumberSorter implements Comparator { public int compare(String a, String b) { String tempa = a.substring(0,4) + a.charAt(6) + a.substring(3,6); String tempb = b.substring(0,4) + b.charAt(6) + b.substring(3,6); return tempa.compareTo(tempb); } }

import java.util.Comparator;

public class NumberLetterSorter implements Comparator { public int compare(String c1, String c2) { String tempc1 = c1.substring(3,6) + c1.charAt(6) + c1.substring(0,4); String tempc2 = c2.substring(3,6) + c2.charAt(6) + c2.substring(0,4); return tempc1.compareTo(tempc2); } }

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

Step: 3

blur-text-image

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 Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago