Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7728067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:37:25+00:00 2026-06-01T05:37:25+00:00

import java.util.Arrays; import java.util.ArrayList; import java.util.Scanner; import java.util.Collections; import java.util.List; public class TennisTournament {

  • 0
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Collections;
import java.util.List;

public class TennisTournament {

  public static void main (String [] args) {
    Scanner input = new Scanner(System.in);
    ArrayList <Integer> nums = new ArrayList<Integer>();
    while (input.hasNextInt()) {
      nums.add(input.nextInt());
    }
    System.out.println(nums);
    tournament(nums);
  }

  public static void tournament(ArrayList <Integer> list) {
    int midPoint = list.size()/2; // returns the index number of half of the lists size
    int midPoint2 = list.size()/2;
    if (list.size() != 1 || midPoint != 1) {
      for (int i = 0; i < midPoint2; i++) { // while is bigger than mid point, increment by one
        if (list.get(i) < list.get(midPoint)) {
          Collections.swap(list, i, midPoint);
        }
        midPoint++;
      }
      System.out.println(list);
      int newPoint = midPoint2/2;
      midPoint2 = newPoint;
    }
    tournament(list);

  }
}

Okay, so I’m quite new to idea of recursion and right now, all I’m getting is an infinite loop. So in the first method, I wanted to analyse to the array by dividing it in half, and and compare the first element of the first half of the array with the first element of the second half of the array, and if the second element was bigger, then swap And that’s all working fine, it’s doing exactly what I want it to do.
[3, 5, 8, 2, 1, 7, 6, 4]
[3, 7, 8, 4, 1, 5, 6, 2]
The next step I want to take is I just want to half the elements i’m working on. So in the first instance, I wanted to half the number of elements i’m working, so instead of 0-list.size, i want it to work on 0-list.size()/2, so it will only swap the first four numbers, and then do it again, on 2 numbers until the mid point becomes one.
Just a little insight on how I could achieve that would be great.
And no, not homework.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:37:27+00:00Added an answer on June 1, 2026 at 5:37 am

    I guess you need to stop splitting, when the list size is smaller than 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.io.*; import java.util.Scanner; import java.util.StringTokenizer; public class Filereader { public static void main(String[]
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class InversionCounter { public static void main(String[]
import java.io.*; import java.util.*; public class Readfilm { public static void main(String[] args) throws
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateDemo { public static void main(String[]
I'm confused by the following code: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class
I have the following Java code: import java.util.Arrays; import java.util.Collections; public class Test {
import java.util.ArrayList; import java.util.Arrays; public class Cloud { private ArrayList<Point> points; private double left;
import java.util.*; public class SimpleArrays { @SafeVarargs public static <T> List<T> asList( T... a
import java.util.HashMap; import java.io.*; import java.util.*; public class Fegan implements Comparable{ HashMap<String, Integer> cart
This code compiles: import java.io.Serializable; import java.util.Arrays; class Test<T extends Arrays & Serializable> {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.