Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package edu.ser222.m02_02; /** * Implements various divide and conquer algorithms. * * Last updated 4/2/2022. * * Completion time: (your completion time) * * @author

package edu.ser222.m02_02;

/**

* Implements various divide and conquer algorithms.

*

* Last updated 4/2/2022.

*

* Completion time: (your completion time)

*

* @author (your name), Acuna, Sedgewick and Wayne

* @verison (version)

*/

import java.util.Random;

public class CompletedMerging implements MergingAlgorithms {

//TODO: implement interface methods.

@Override

public Queue mergeQueues(Queue q1, Queue q2) {

//TODO: implement this!

return null;

}

@Override

public void sort(Comparable[] a) {

//TODO: implement this!

}

@Override

public Comparable[] mergesort(Comparable[] a) {

//TODO: implement this!

return null;

}

@Override

public Comparable[] merge(Comparable[] a, Comparable[] b) {

//TODO: implement this!

return null;

}

@Override

public void shuffle(Object[] a) {

//TODO: implement this!

}

/**

* entry point for sample output.

*

* @param args the command line arguments

*/

public static void main(String[] args) {

Queue q1 = new ListQueue<>(); q1.enqueue("E"); q1.enqueue("L"); q1.enqueue("O"); q1.enqueue("R"); q1.enqueue("T");

Queue q2 = new ListQueue<>(); q2.enqueue("A"); q2.enqueue("E"); q2.enqueue("M"); q2.enqueue("P"); q2.enqueue("S"); q2.enqueue("X");

Queue q3 = new ListQueue<>(); q3.enqueue(5); q3.enqueue(12); q3.enqueue(15); q3.enqueue(17); q3.enqueue(20);

Queue q4 = new ListQueue<>(); q4.enqueue(1); q4.enqueue(4); q4.enqueue(12); q4.enqueue(13); q4.enqueue(16); q4.enqueue(18);

MergingAlgorithms ma = new CompletedMerging();

//Q1 - sample test cases

Queue merged1 = ma.mergeQueues(q1, q2);

System.out.println(merged1.toString());

Queue merged2 = ma.mergeQueues(q3, q4);

System.out.println(merged2.toString());

//Q2 - sample test cases

String[] a = {"S", "O", "R", "T", "E", "X", "A", "M", "P", "L", "E"};

ma.sort(a);

assert isSorted(a);

show(a);

//Q3 - sample test cases

String[] b = {"S", "O", "R", "T", "E", "X", "A", "M", "P", "L", "E"};

ma.shuffle(b);

show(b);

ma.shuffle(b);

show(b);

}

//below are utilities functions, please do not change them.

//sorting helper from text

private static boolean less(Comparable v, Comparable w) {

return v.compareTo(w) < 0;

}

//sorting helper from text

private static void show(Comparable[] a) {

for (Comparable a1 : a)

System.out.print(a1 + " ");

System.out.println();

}

//sorting helper from text

public static boolean isSorted(Comparable[] a) {

for (int i = 1; i < a.length; i++)

if (less(a[i], a[i-1]))

return false;

return true;

}

}

Please implement anything that says TODO

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions