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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:35:21+00:00 2026-06-02T08:35:21+00:00

I have an exercise where I need to use a WebMethod to perform a

  • 0

I have an exercise where I need to use a WebMethod to perform a bubble sort, Ascending and Descending.

This is the method that I use for an Ascending sort for example.

[WebMethod]
public Boolean larger(int a, int b)
{
    Boolean isLarger;
    if (a < b)
    {
        isLarger = false;
    }
    else
    {
        isLarger = true;
    }
    return isLarger;
}

This is the C# application that accesses the method to perform the sort.
We are required to sort 5 numbers only.

ArrayList numbersAL = new ArrayList();

for (int i = 0; i < 5; i++)
{
     numberInput = Int32.Parse(Console.ReadLine());
     numbersAL.Add(numberInput);
}
Boolean swap;

do
{
     swap = false;

     for (int j = 0; j < numbersAL.Count - 1; j++)
     {                          
          Console.WriteLine("output");
          int a = (int)numbersAL[j];
          int b = (int)numbersAL[j + 1];

          result = s.larger(a, b);

          if (result)
          {
               temporary = a;
               a = b;
               b = temporary;
               swap = true;                                           
          }                                                            
     }
} while (swap == true);

With this however I get an infinite loop and I guess the reason for this is that the numbers in the ArrayList still remains in the original order after the numbers were swapped around and then the process just repeats itself.

How could I rectify this situation.

Kind regards

  • 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-02T08:35:24+00:00Added an answer on June 2, 2026 at 8:35 am

    Your swap is swapping the local variables a and b. You need to swap the corresponding numbers in numbersAL.

    if (result)
    {
        int temporary = (int)numbersAL[j];
        numbersAL[j] = numbersAL[j+1];
        numbersAL[j+1] = temporary;
        swap = true;                                           
    }                    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is indeed a sort of exercise I have to complete but a little
I have another exercise I have to do that I really need help with.
I have been busy with a exercise where I need to compare a winning
I have a code like this, which is solved by me following a exercise
In XCode 4.2, I have some logic tests that I want to exercise against
I have a couple of Python functions that I use to make game development
I have a mission critical Perl-CGI server-side application that I need to extend or
I have an exercise to do where I need to code in C, commands
I have a little exercise where I need to access data from a view
I have a simple exercise where I call a Thread and subsequently the run()

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.