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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:43:20+00:00 2026-05-28T18:43:20+00:00

Hi I have the following bubble sort algorithm (generic code taken from another site)

  • 0

Hi I have the following bubble sort algorithm (generic code taken from another site) and I would like to have numbers next to each element of the array as it gets sorted. For example when I run it and it sorts out the array, next to each element it should have the number 1 as this is the first of many sorting algorithms I am using. So to demonstrate:
My results after sorting will look like:

4 1
27 1
54 1
321 1
542 1
654 1
887 1
1023 1

As you can see, the number 1 is inserted into the each element of the array as it is being sorted in the algorithm. Can someone help me with this?

Sorting algorithm:

public static <E extends Comparable<? super E>> void bubbleSort(E[] comparable) {
    boolean changed = false;
    do {
        changed = false;
        for (int a = 0; a < comparable.length - 1; a++) {
            if (comparable[a].compareTo(comparable[a + 1]) > 0) {
                E tmp = comparable[a];
                comparable[a] = comparable[a + 1];
                comparable[a + 1] = tmp;
                changed = true;
            }
        }
    } while (changed);
}
  • 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-28T18:43:21+00:00Added an answer on May 28, 2026 at 6:43 pm

    After you have sorted do the following to print:

    for (int i = 0 ; i < comparable.length ; i++){
        System.out.println(comparable[i] + " 1" );
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to implement a bubble sort. I have the following code that I
i am implementing the simple bubble sort algorithm using CUDA, and i have a
I have a piece of Perl code somewhat like the following (strongly simplified): There
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
The following code shows a normal event and a routed event. Here I have
I have the following app, that's like a chat, so I'm programmatically creating some
Have following validation for year value from text input: if (!year.match(new RegExp('\\d{4}'))){ ... }
I am using the following ASM routine to bubble sort an array. I want

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.