Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-01-2007, 03:20 AM
Member
 
Join Date: Nov 2007
Posts: 8
Rep Power: 0
Warren is on a distinguished road
Default String []Array
how can Bubble Sort be implemented on String Array?
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-01-2007, 05:33 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
Rep Power: 0
staykovmarin is on a distinguished road
Default
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
Rep Power: 0
Warren is on a distinguished road
Default
thats for integers. anyway thanx.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-01-2007, 08:37 AM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
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
Rep Power: 0
staykovmarin is on a distinguished road
Default
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
Reply

Bookmarks

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

BB 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
Convert a vector to a string array orchid New To Java 4 02-24-2010 03:31 AM
How i add string array in vector susan New To Java 7 02-12-2009 02:32 PM
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


All times are GMT +2. The time now is 11:38 AM.



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