Experiencing difficulty with a bubblesort exercise <p>I have an exercise where I need to use a WebMethod to perform a bubble sort, Ascending and Descending. </p> <p>This is the method that I use for an Ascending sort for example.</p> <pre><code>[WebMethod] public Boolean larger(int a, int b) { Boolean isLarger; if (a &lt; b) { isLarger = false; } else { isLarger = true; } return isLarger; } </code></pre> <p>This is the C# application that accesses the method to perform the sort. We are required to sort 5 numbers only.</p> <pre><code>ArrayList numbersAL = new ArrayList(); for (int i = 0; i &lt; 5; i++) { numberInput = Int32.Parse(Console.ReadLine()); numbersAL.Add(numberInput); } Boolean swap; do { swap = false; for (int j = 0; j &lt; 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); </code></pre> <p>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.</p> <p>How could I rectify this situation.</p> <p>Kind regards</p>