Learn how to Make Money Online | Free Tech Magazines
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Articles / Source Code > Programming > C#

Discuss / Comment Copy HTML to Clipboard  Copy BBCode to Clipboard  Add to del.icio.us  Add to Google  Digg it  Add to Yahoo !  Add to Windows Live  Add to Facebook  Add to StumbleUpon 
 
Bookmarks Article Tools Search this Article Display Modes

Bubble Sort in C#

By pradeep pradeep is offline

On 29th May, 2007
Lightbulb Bubble Sort in C#

ADVERTISEMENT
Show Printable Version Email this Page Subscription Add to Favorites Copy Bubble Sort in C# link

Author

pradeep ( Team Leader )

Yet to provide details about himself


All articles By pradeep

Recent Articles

Similar Articles

Implementing Bubble Sort in C#

Code: CSharp
/*
 **    Simple class to sort an array in ascending order using bubble sort
 **    @author: Tanaz Kerawala
 **    @author: S Pradeep
 **    @date: 5/29/2007
 */

 
 using System;
 
 class AscendingBubbleSort
 {
     public static void Main()
     {
         int i,j,t;
         int []p=new int[10];
         int []q=new int[10];
         int []c=new int[20];
         for(i=0;i<10;i++)
         {
             Console.WriteLine("Enter Value");
             p&#91;i]=int.Parse(Console.ReadLine());
         }
         for(i=0;i<10;i++)
         {
             Console.WriteLine("Enter Value");
             q&#91;i]=int.Parse(Console.ReadLine());
         }
 
         if(j<10)
             c&#91;j]=p[j];
         else
             c&#91;j]=q[j-10];
         
         // Sorting: Bubble Sort
         for(i=0;i<20;i++)
         {
             for(j=0;j<20;j++)
             {
                 if(c&#91;i]>c[j])
                 {
                     t=c&#91;i];
                     c&#91;i]=c[j];
                     c&#91;j]=t;
                 }
             }
         }
 
         // Print the contents of the sorted array
         for(i=0;i<20;i++)
         {
             Console.WriteLine (c&#91;i]);
         }
     }
     
 }
Old 09-06-2007, 03:19 AM   #2
sushovan.mukherjee
Light Poster
 
sushovan.mukherjee's Avatar
 
Join Date: Sep 2007
Location: Kolkata
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
sushovan.mukherjee is on a distinguished road
Send a message via MSN to sushovan.mukherjee Send a message via Yahoo to sushovan.mukherjee

Re: Bubble Sort in C#


Boss this code is not working..
__________________
Yours truely, Sushovan Mukherjee
Mo :: + 91 9339270774
mukherjee.sushovan@gmail.com sushovan.mukherjee@yahoo.com
sushovan.mukherjee is offline   Reply With Quote
Old 09-25-2007, 09:27 PM   #3
clocking
Ambitious contributor
 
clocking's Avatar
 
Join Date: Jun 2007
Posts: 122
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 3
clocking is on a distinguished road

Re: Bubble Sort in C#


Hi, My friend.
Can you show me the way programming the C# program?
Can you write a code to solve some problem( Please, beginning to the End).
thanks.
Best regards.
clocking is offline   Reply With Quote
Old 09-26-2007, 10:21 AM   #4
shabbir
Go4Expert Founder
 
shabbir's Avatar
 
Join Date: Jul 2004
Location: On Earth
Posts: 10,943
Thanks: 35
Thanked 167 Times in 139 Posts
Rep Power: 10
shabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud of
Send a message via Yahoo to shabbir

Re: Bubble Sort in C#


Yes the above code is not working and following are the compile time errors. j is used without being initialized. Also the sorting does not work if we have the j set as zero.
shabbir is offline   Reply With Quote
Old 01-02-2008, 10:54 PM   #5
ahabeebur
Newbie Member
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
ahabeebur is on a distinguished road

Re: Bubble Sort in C#


5n
ahabeebur is offline   Reply With Quote
Old 07-02-2008, 01:09 PM   #6
Saveera
Newbie Member
 
Join Date: Jul 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Saveera is on a distinguished road

Re: Bubble Sort in C#


The above code is not run,I think you should write the Integer.parseInt at the place of Parse
Saveera is offline   Reply With Quote
Old 07-02-2008, 01:12 PM   #7
Saveera
Newbie Member
 
Join Date: Jul 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Saveera is on a distinguished road

Re: Bubble Sort in C#


hello
Saveera is offline   Reply With Quote
Old 12-20-2008, 10:20 AM   #8
Maledikt
Newbie Member
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Maledikt is on a distinguished road

Re: Bubble Sort in C#


I believe the fault is the fact that the '[' character is replaced by "c[" due to some error in the [code] constructor inside the web-script hosting this forum.

Hoping this is the case and that I'm actually of some help,
Maledikt
Maledikt is offline   Reply With Quote
Old 04-17-2009, 03:56 PM   #9
danhl
Newbie Member
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
danhl is on a distinguished road

Re: Bubble Sort in C#


Here comes updated code.

Code:
using System;  
class AscendingBubbleSort 
{     
    public static void Main()
    {
        int i = 0,j = 0,t = 0;
        int []c=new int[20];
        for(i=0;i<20;i++)
        {
            Console.WriteLine("Enter Value p[{0}]:", i);
            c[i]=int.Parse(Console.ReadLine());
        }
        // Sorting: Bubble Sort
        for(i=0;i<20;i++)
        {
            for(j=i+1;j<20;j++)
            {
                if(c[i]>c[j])
                {
                    Console.WriteLine("c[{0}]={1}, c[{2}]={3}", i, c[i], j, c[j]);
                    t=c[i];
                    c[i]=c[j];
                    c[j]=t;
                }
            }
        }
        Console.WriteLine("Here comes the sorted array:");
        // Print the contents of the sorted array
        for(i=0;i<20;i++)
        {
            Console.WriteLine ("c[{0}]={1}", i, c[i]);
        }
    }
}
danhl is offline   Reply With Quote
Discuss / Comment Copy HTML to Clipboard  Copy BBCode to Clipboard  Add to del.icio.us  Add to Google  Digg it  Add to Yahoo !  Add to Windows Live  Add to Facebook  Add to StumbleUpon 


Currently Active Users Reading This Article: 1 (0 members and 1 guests)
 
Article Tools Search this Article
Search this Article:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads / Articles
Thread Thread Starter Forum Replies Last Post
Overview of C# Sanskruti C# 2 09-23-2009 10:00 PM
100 Multiple choice questions in C coderzone C-C++ 98 08-26-2009 12:17 AM
Data Types in C# pradeep C# 20 02-21-2008 11:18 AM
Sorting Algorithms saomcol Programming 5 09-30-2007 01:50 PM
error in compilation of binary tree code in c rahul_2550 C-C++ 9 03-26-2007 11:31 AM

 

All times are GMT +5.5. The time now is 05:54 AM.