Help BubbleSort Array wont run?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2006
Posts: 1
Reputation: Big John is an unknown quantity at this point 
Solved Threads: 0
Big John Big John is offline Offline
Newbie Poster

Help BubbleSort Array wont run?

 
0
  #1
Nov 20th, 2006
I'm just learning java and this is my first sort program. I can't get it to run. I sure could use some help.


public class SortCharArray
{
public static void main(String[] args) throws Exception
{
char[] someChars = new char[10];
int x;



for(x = 0; x < someChars.length; ++x)
{
System.out.print("Enter a character ");
someChars[x] = (char)System.in.read();
System.in.read(); System.in.read();

}

System.out.println("Before sort");
for(x = 0; x < someChars.length; ++x)
System.out.print(someChars[x] + " ");

bubbleSort(someChars, someChars.length);

System.out.println("\nAfter sort");
for(x = 0; x < someChars.length; ++x)
System.out.print(someChars[x] + " ");
System.out.println();

}

public static void bubbleSort(char[] array, int len)
{
int a, b;
char temp;
int highSubscript = len - 1;
for(a = 0; a < highSubscript; ++a)
{
for(b = 0; b < highSubscript; ++b)
if(array[b] > array[b = 1])
{
temp = array[b];
array[b] = array[b + 1];
array[b + 1] = temp;
}
}
}

}
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,416
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 257
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Help BubbleSort Array wont run?

 
0
  #2
Nov 20th, 2006
Well, supplying the errors you are getting would be helpful.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,468
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Help BubbleSort Array wont run?

 
0
  #3
Nov 20th, 2006
Please use code tags when posting code. Read the information in the links below.

This is how I code it in c/c++:

  1. for(a = 0; a < highSubscript-1; ++a)
  2. {
  3. for(b = 0; b < highSubscript; ++b)
  4. {
  5. if(array[a] > array[b])
  6. {
  7. temp = array[a];
  8. array[a] = array[b];
  9. array[b] = temp;
  10. }
  11. }
  12. }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 23
Reputation: kimbokasteniv is an unknown quantity at this point 
Solved Threads: 0
kimbokasteniv kimbokasteniv is offline Offline
Newbie Poster

Re: Help BubbleSort Array wont run?

 
0
  #4
Nov 22nd, 2006
I think you may be best off using KeyboardReader to take input.
And you definitely have to use Ancient Dragon's suggestion for the bubble sort.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC