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 7670173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:45:41+00:00 2026-05-31T15:45:41+00:00

I think I have done the selection sort but I am not sure. Is

  • 0

I think I have done the selection sort but I am not sure. Is this really an implementation of selection sort?

static void selectionSort()
    {
        int min = Integer.MIN_VALUE;
        int n = 0;
        for(int I=0; I<arraySize; I++)
        {

            min = dataArray[I];
            for(int j=I; j<n; j++)
            {
                if(dataArray[min]<dataArray[j])
                  {
                        min = j;
                        if(dataArray[min] < dataArray[I])
                        {
                            int temp = dataArray[I];
                            dataArray[I] = dataArray[min];
                            dataArray[min] = temp;
                        }
                  }
            }
        }   
    }
  • 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-05-31T15:45:42+00:00Added an answer on May 31, 2026 at 3:45 pm

    I’m not sure I understand how your algorithm works at all. Specifically, you do

    min = dataArray[i];
    

    and then later

    dataArray[min]<dataArray[j]
    

    i.e. you treat min both as a value in the array, and an index.

    Selection sort works as follows:

    1. Find the minimum value in the list
    2. Swap it with the value in the first position
    3. Repeat the steps above for the remainder of the list

    (source)


    The changes required for your code to accurately implement selection sort would be the following:

    1. Change the inner loop to just find the index of the smallest element. Call it minIndex for instance.
    2. Do the swapping after the inner loop. i.e., swap element at index I with minIndex.

    Oh, and as DonCallisto points out in the comments, you may want to do n = dataArray.length instead of n = 0 🙂

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

Sidebar

Related Questions

I don't think this can be done cleanly, but I'll ask anyway. I have
Hi I have done this task. But I have to clarify some thing. I
I think I have this working but I need advice. I'd like to know
I have done everything that is on the web (i think) i have the
I think I might have done something right, headByRating and headByName both refer to
I have often seen the spinning gears OpenGL example ( I think originally done
I think I have a basic understanding of REST, but something I'm stuck on
Ok, lemme start out by saying Im new to this! LOL I have done
ReSharper has a nice feature called extend selection: by pressing CTRL+W (I think this
I think I have a synchronization problem...It may be too basic..Please help.. I have

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.