Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-01-2007, 03:20 AM
Member
 
Join Date: Nov 2007
Posts: 8
Warren is on a distinguished road
String []Array
how can Bubble Sort be implemented on String Array?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-01-2007, 05:33 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Java: Bubble Sorts
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-01-2007, 06:03 AM
Member
 
Join Date: Nov 2007
Posts: 8
Warren is on a distinguished road
thats for integers. anyway thanx.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-01-2007, 08:37 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,146
hardwired is on a distinguished road
String implements the Comparable interface so you can use
str1.compareTo(str2) and use the return value for ordering.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-01-2007, 09:03 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
They are for integers, but they still show how the basic of a Bubble Sort works.
Code:
public static void bubleSort(String[] ar) { int n = ar.length; for (int pass = 1; pass < n; pass++) { for (int i = 0; i < n - pass; i++) { if (ar[i].compareTo(ar[i + 1]) > 0) { String tmp = ar[i]; ar[i] = ar[i + 1]; ar[i + 1] = tmp; } } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP to output Java String Array irenavassilia JavaServer Pages (JSP) and JSTL 0 03-31-2008 05:11 PM
Help with string and array in java zoe New To Java 1 08-07-2007 07:12 AM
I can't seem to pass the value of a string variable into a string array mathias Java Applets 1 08-03-2007 11:52 AM
How i add string array in vector susan New To Java 1 07-16-2007 06:44 AM
Convert a vector to a string array orchid New To Java 2 05-06-2007 08:14 AM


All times are GMT +3. The time now is 04:22 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org