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

  • SEARCH
  • Home
  • 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 7748399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:46:32+00:00 2026-06-01T10:46:32+00:00

I have a homework assignment to sort an array in ascending order. Obviously, this

  • 0

I have a homework assignment to sort an array in ascending order. Obviously, this is to be done manually without using any kind of sort() function.

I figured to do it, I would need two for loops: the first one will loop through the existing array and create a temporary value with the value and index of the array. The second loop will compare the temporary values to the existing values and sort them. I keep trying to write the code, but I just can’t seem to get it right. Here is the latest method I came up with:

public int[] sortArray (int[] inArray)
{
    //Construct the array we're using here
    int[] newArray = inArray;

    for(int x = 0; x < a.length; x++) //a.length = # of indices in the array
    {
        int tempValue = a[x];
        int tempIndex = x;

        for(int y = 0; y < a.length; y++)
        {
            if(tempValue < a[y])
            {
                newArray[x] = tempValue;
            }
        }
    }

    return newArray;
}

I’m pretty sure this is incorrect, but if someone could push me in the right direction it would be very appreciated!

  • 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-01T10:46:33+00:00Added an answer on June 1, 2026 at 10:46 am

    You have a nearly OK version of the Selection Sorter. You need to start your y at x+1, not at 0. Otherwise you’re re-scanning the sorted portion of the array. You should also note that selection sort is an in-place algorithm; if you are looking to make a copy of the array, you should use Arrays.copy method, otherwise int[] newArray = inArray;
    is creating an alias, not a copy. Finally, the if statement in the nested loop should swap a[x] and a[y], not simply put tempValue in:

    if(newArray[x] < newArray [y]) {
        int tempValue = newArray[y];
        newArray[y] = newArray[x];
        newArray[x] = tempValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(this is indirectly a part of a much larger homework assignment) I have something
I have this homework assignment where the user is asked to input numbers and
I have done a homework assignment, here is the problem statement: Your program should
Im almost done with a homework assignment that multiplies polynomials and has to have
I have a homework assignment and I've done the bare minimum of the assignment,
This is part of a homework assignment. What we have to do is write
Continuing on this problem , but I'll reiterate: For a homework assignment I have
I need to do this homework assignment using prolog (SWI-flavor) and cant get my
I am working on a homework assignment, and I have almost everything done except
I have a homework assignment that asks to create an order form. The order

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.