Forums Register Login

Program to sort the characters in the string

+Pie Number of slices to send: Send
Could you please help me out the java program to sort the characters for the given string without using sort() method?
For example, if we are giving the input as "sai",the output should be "ais".
+Pie Number of slices to send: Send
Sure. What ideas and/or code do you have so far?
+Pie Number of slices to send: Send
There is a vast amount of different sorting algorithms, bubblesort being the easiest and slowest, but works fine in a developing context.. Otherwise you've got selection sort, quicksort and heapsort to mention a few.

Which one do you want to use?
+Pie Number of slices to send: Send
I'd just get the char[] and use Arrays.sort() on that one.

Seeing as you can't or don't want to use that approach I think this is a homework assignment, and you have to write your own sorting code.

Check out Wikipedia and Google, there are enough examples to be found.
+Pie Number of slices to send: Send
I want to know the logic behind sort() method.So that I asked this program without using sort().
Could you please tell me this progm using bubble sort method
+Pie Number of slices to send: Send
This explains the algorithm that a bubble sort uses. Try implementing it in Java and if you have any problems, show us your code.
+Pie Number of slices to send: Send
The Arrays.sort() method is overloaded and use different sorting algorithms depending on what type of array it is supposed to sort.

If you read the source file (Arrays.class) you will see many examples of different sorting algorithms.
+Pie Number of slices to send: Send
I would say that Arrays.sort() always uses the same algorithm - it just has multiple implementations for different data types. It's a good algortihm, certainly, much faster than a bubble sort. But for a beginner it may well be easier to understand the bubble sort.
+Pie Number of slices to send: Send
 


I would say that Arrays.sort() always uses the same algorithm - it just has multiple implementations for different data types. It's a good algortihm, certainly, much faster than a bubble sort. But for a beginner it may well be easier to understand the bubble sort.



Well, sort of..
I found Insertion sort (on smallest arrays), Mergesort (on Object arrays) and quicksort elsewhere.
[ October 23, 2007: Message edited by: Jim Yingst ]
+Pie Number of slices to send: Send
Sorry about the edit above - I accidentally hit edit rather than reply, but I was able to restore the original text.

Hm, OK. I would argue that using insertion sort for small arrays isn't based on the type of the array and overloading. But I didn't realize that both quicksort and heapsort were in there; thanks.
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3009 times.
Similar Threads
Using special characters in java
Comparing = sign and [
Strings
Algorithm for searching for a scrambled word in a list
problem in my String program
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:03:50.