Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 probelm with this code!(c#)

views
     
TSming1
post Feb 17 2006, 04:35 PM, updated 20y ago

Getting Started
**
Junior Member
252 posts

Joined: Jan 2005
This is a code for sorting the ascending order.Altough i had this code, but i don't really know the concept for this code and how does this code work actually......

for (int count = findings.Length - 1; count > 0; count--)
{
for (int countInner = 0; countInner < count; countInner++)
{
if (findings[countInner + 1] <= findings[countInner])
{
temp = findings[countInner];
findings[countInner] = findings[countInner +1];
findings[countInner +1] = temp;
}
}
}
for (int count = 0; count < findings.Length; count++)
{
Console.Write("{0}\t", findings[count]);
}

Can anyone explain to me????
anthony_yio
post Feb 17 2006, 04:57 PM

........
Group Icon
Elite
1,828 posts

Joined: Jan 2003


QUOTE(ming1 @ Feb 17 2006, 04:35 PM)
This is a code for sorting the ascending order.Altough i had this code, but i don't really know the concept for this code and how does this code work actually......

for (int count = findings.Length - 1; count > 0; count--)
        {
            for (int countInner = 0; countInner < count; countInner++)
            {
                if (findings[countInner + 1] <= findings[countInner])
                {
                    temp = findings[countInner];
                    findings[countInner] = findings[countInner +1];
                    findings[countInner +1] = temp;
                }
            }
        }
        for (int count = 0; count < findings.Length; count++)
        {
            Console.Write("{0}\t", findings[count]);
        }

Can anyone explain to me????
*
I think it is a bubble sort. Check your algorithm text book for good and in depth explanation.
TSming1
post Feb 17 2006, 05:27 PM

Getting Started
**
Junior Member
252 posts

Joined: Jan 2005
yes it is a bubble sort....i do not have any text book,that's why i'm here finding for assistance....

TSming1
post Feb 17 2006, 05:30 PM

Getting Started
**
Junior Member
252 posts

Joined: Jan 2005
besides using this way, is there another easiest way for me to sort number in ascending manner???
anthony_yio
post Feb 17 2006, 06:28 PM

........
Group Icon
Elite
1,828 posts

Joined: Jan 2003


QUOTE(ming1 @ Feb 17 2006, 05:27 PM)
yes it is a bubble sort....i do not have any text book,that's why i'm here finding for assistance....
*
Search for bubble sort in google or any search portal, you would get a lot of hits. (if you do not have off-line reference that is)




This post has been edited by anthony_yio: Feb 17 2006, 07:04 PM
silverhawk
post Feb 17 2006, 08:10 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


The bubble sort works fine, but there are other faster sorting algorithms out there.
The code is fairly straight forward, you SHOULD be able to understand the bubble sort by just reading the code.

The bubble sort works by checking the first value with the other values in the list. If the value is smaller, they are swapped. When the entire list is checked with the first value, it goes to the 2nd value and repeats the process.

 

Change to:
| Lo-Fi Version
0.0153sec    0.37    5 queries    GZIP Disabled
Time is now: 23rd December 2025 - 09:17 AM