iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 13, 2008
Rainbow Links
EarthWeb.com
 
May 13, 2008
MySpace Profile Page Resources
HTML Goodies
 
May 13, 2008
How to Upload Your Photos onto the Web
HTML Goodies
 
May 13, 2008
Email Marketing for MySpace Artists
HTML Goodies
 
May 13, 2008
Top Online Marketing Techniques
HTML Goodies
 
May 13, 2008
I want to create a site just like ____, is that a violation of...
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /Java

using bubble sort in java 

  Views:    11964
  Votes:    8
by Brendan Murtagh 12/06/03 Rating: 

Synopsis:

below is a tutorial on using a randomly generated array of characters which are converted into their integer value using casting and then sorted using a bubble sort. the char values are then displayed unsorted and sorted for varification.
Pages: 
The Article

public class bubble {
   /* main function */
   public static void main(String[] args)
 {
  int random, flag, temp;
  int numarray[] = new int[100]; /* declares a new integer array holding from 0 to 99 */
  char letarray[] = new char[100]; /* declares a new character array holding 0 to 99 */
  char tamp;
  System.out.print("\n\nUnsorted Array\n");
  /* for loop goes here for printing out the array of chars */
  for(int i = 0; i < 100; i++)
   {
    random = (int)(Math.random()*90) + 1;
     if (random != 0 && random >= 65)
      {
       numarray[i] = random;
       letarray[i] = (char)random;
       System.out.print("\t" + letarray[i] + " ");
      }
   }

  do { /* do...while loop to sort the array */
   flag=0;
   for(int j=0; j<99; j++)
    {
     if(numarray[j] > numarray[j+1])
      {
       temp = numarray[j];
       tamp = letarray[j];
       numarray[j] = numarray[j+1];
       numarray[j+1] = temp;
       letarray[j] = letarray[j+1];
       letarray[j+1] = tamp;
       flag = 1;
    }
   }
  } while(flag!=0); /* end of bubble sort */
  System.out.print("\nSorted Array");
  for(int k=0; k<100; k++) /* print sorted array */
   {
    System.out.print("\t" + letarray[k] + " ");
   }
  }
 }
Pages: 



 
  Sponsors