Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How do I sort strings without using the sort method?

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do I sort strings without using the sort method?

    	public static void idNumberSort(String[] array)
    	{
    		int startScan, index, maxIndex, maxValue;
     
    		for (startScan = 0; startScan < (array.length-1); startScan++)
    		{
    			maxIndex = startScan;
    			maxValue = array[startScan];
    			for(index = startScan + 1; array[index]compareToIgnoreCase(maxValue) > 0; index++)
    			{
    				if (array[index] > maxValue)
    				{
    					maxValue = array[index];
    					maxIndex = index;
    				}
    			}
    			array[maxIndex] = array[startScan];
    			array[startScan] = maxValue;
    		}
    	}

    I wanted to sort the strings in descending order. My teacher won't let us use the sort method.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How do I sort strings without using the sort method?

    See Sorting algorithm - Wikipedia, the free encyclopedia for a list of sorting algorithms.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How do I sort strings without using the sort method?

    You can use methods in the String class to compare two strings.

Similar Threads

  1. [SOLVED] Bucket or Bin Sort
    By itispj in forum Java Theory & Questions
    Replies: 1
    Last Post: October 15th, 2011, 06:14 PM
  2. Using a Generic Insertion Sort method
    By dubois.ford in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2011, 06:08 PM
  3. How to sort an ArrayList of Strings?
    By noFear in forum Java Theory & Questions
    Replies: 6
    Last Post: September 15th, 2010, 03:23 PM
  4. bubble sort and selection sort on strings
    By Sir Saula in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2010, 09:44 AM
  5. Replies: 6
    Last Post: October 20th, 2009, 06:33 AM