Programming Alogorithm Series: Bubble Sort

using System;

namespace BubbleSort

{

class Program

{

static void Main(string[] args)

{

int[] array = new int[] {2,5,7,1,9,0,3,4,2,6,7,5};

// Before sorting

for (int i = 0; i < array.Length - 1; i++)

{

Console.Write(array[i]);

}

Console.ReadLine();

ArraySort.SortArray(array);

// After sorting

for (int i = 0; i < array.Length - 1; i++)

{

Console.Write(array[i]);

}

Console.ReadLine();

}

}

class ArraySort

{

public static void SortArray(int[] numbers)

{

int tempInt;

for (int i = (numbers.Length-1); i >=0; i--)

{

for (int j =1; j <=i; j++)

{

if (numbers[j-1] > numbers[j])

{

tempInt = numbers[j-1];

numbers[j-1] = numbers[j];

numbers[j] = tempInt;

}

}

}

}

}

}

Published Tuesday, September 19, 2006 12:00 AM by sanjeebsarangi
Filed under:

Comments

Thursday, September 20, 2007 4:10 PM by Tosa

# re: Programming Alogorithm Series: Bubble Sort

This is really a brilliant way to create and use a Sort class.

However, there was a bug in the code

instead of:

for (int i = 0; i < array.Length - 1; i++)

this is more accurate

for (int i = 0; i < array.Length; i++)

because '<' is used.

Sunday, December 13, 2009 11:33 PM by cash advance

# re: Programming Alogorithm Series: Bubble Sort

Good Morning!!! weblogs.asp.net is one of the most excellent informational websites of its kind. I enjoy reading it every day. weblogs.asp.net rocks!

Wednesday, July 20, 2011 7:48 PM by mens leather belts

# re: Programming Alogorithm Series: Bubble Sort

What a great memory! We used to make covered buttons when we were little with Mom!!

Wednesday, July 20, 2011 11:17 PM by Prada handbags 2011

# re: Programming Alogorithm Series: Bubble Sort

Nice to be visiting your blog again, it has been months for me. Well this article that Ive been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.

Monday, July 25, 2011 10:59 PM by supra tk society

# re: Programming Alogorithm Series: Bubble Sort

You managed to hit the nail upon the top as well asand alsoand defined out the whole thing without having side effectside-effects , people cancould take a signal. Will likelyprobably be back to get more. Thanks

Friday, August 05, 2011 5:12 AM by cheap True Religion jeans

# re: Programming Alogorithm Series: Bubble Sort

Its really good to be part of a community that you know you can contribute something worthwhile.thanks for the share.<a href="www.cheaptruereligionsales.com/" title="cheap True Religion jeans">cheap True Religion jeans</a>

Leave a Comment

(required) 
(required) 
(optional)
(required)