Bubble Sort Program C-Sharp Code.

WHAT IS BUBBLE SORT :


The bubble sort makes multiple passes through a list. It compares adjacent items and exchanges those that are out of order. Each pass through the list places the next largest value in its proper place. In essence, each item “bubbles” up to the location where it belongs.

GRAPHICAL VIEW OF BUBBLE SORT:


CODING: 

namespace BubbleSortForICS {    
 class Program 
    {         
               static void Main(string[] args)        
 { 

            Console.WriteLine("=======Bubble Sorting Ascending and Desending Order=======");   
          Console.WriteLine("How many number you want to save"); 
            int a = Convert.ToInt32(Console.ReadLine());        
     int [ ] num=new int[a];            
 Console.WriteLine("Input Numbers");    
         for(int i=0;i<a;i++)          
   {            
    
 num[i] = Convert.ToInt32(Console.ReadLine());

     } 

            int temp = 0;        
     for(int i=0;i<a;i++)             
{                
 for(int j=0;j<a-1;j++)    
             {                  
  if (num[j] > num[j+1])    
                 {  
     temp = num[j]; 
  num[j] = num[j + 1];                       
  num[j + 1] = temp;           
          }             
    }           
  } 

            Console.WriteLine("Sorted Values in Ascending Order");      
       for(int i=0;i<a;i++)        
     {                 
Console.WriteLine(num[i]);      
       } 

            for (int i = 0; i < a; i++)  
           {                 
for (int j = 0; j < a - 1; j++)         
        {                   
  if (num[j] < num[j + 1])      
               {                      
   temp = num[j];           
   num[j] = num[j + 1];   
   num[j + 1] = temp;                    
 }               
  }           
  } 

            Console.WriteLine("Sorted Values in Descending Order");      
       for (int i = 0; i < a; i++)             
{                
            Console.WriteLine(num[i]);           
  } 
        }  
   } 
}

After Doing the above coding the press ctrl + F5 and execute your program the output of your is like this:

This is Bubble Sort Program.
Bubble Sort Program C-Sharp Code. Bubble Sort Program C-Sharp Code. Reviewed by Developer Planet on October 17, 2018 Rating: 5

1 comment:

  1. Bubble Sort Program C-Sharp Code. - Developer Planet >>>>> Download Now

    >>>>> Download Full

    Bubble Sort Program C-Sharp Code. - Developer Planet >>>>> Download LINK

    >>>>> Download Now

    Bubble Sort Program C-Sharp Code. - Developer Planet >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete

Advertising

Powered by Blogger.