I have an array of 50 elements each element has a string with no more than 50 letters. i need to sort these alphabetically.
what is an easy way of doing this.
I have an array of 50 elements each element has a string with no more than 50 letters. i need to sort these alphabetically.
what is an easy way of doing this.
Bubble sort could be one good way to do it
>Bubble sort could be one good way to do it
Correction, bubble sort would be an easy way to do it. Bubble sort is never a good solution outside of the classroom
-Prelude
My best code is written with the delete key.
He wanted an easy way and bubble sort is an easy way so there for it is a good solution to his question.
>there for it is a good solution to his question
That's debatable.
-Prelude
My best code is written with the delete key.
Ok he have an array of 50 elements. How big speed difference do you think he would get if he used a highly sofisticated sort algoritm? Face it. Sometimes VB is better then C and some times bubble is better. To say that bubble sort is "never" a good solution outside the class room is alittle bit to strong. It all depends on the applicartion and when your project needs to be done. In lala land it is cool to spend tons of time on things that doesn't necesary matters but not in real life.
>In lala land it is cool to spend tons of time on things that
>doesn't necesary matters but not in real life.
Oh please, next you'll be trying to tell me that insertion or selection sort is sooo much harder to implement than bubble sort. Both are faster, and just as easy to write.
And as long as we're talking about real life, let's think of it this way. Sorting is probably the most resource intensive operation you can perform in a program, programs usually have a very long lifespan and are continually pushed to handle more and more input, if you spent any time in the "real world" instead of the class room then you would understand that 50 today means 50000 tommorow. I'd rather be using an efficient sorting method from the start so that I don't have to deal with the embarassment of having to go back in and change the algorithm because the program was taking days to sort input. There's also potential for losing your job if that happens too.
The only time you see bubble sort in "real life" is when novices who are fresh out of schools that teach nothing but bubble sort manage to sneak it by their supervisors.
-Prelude
My best code is written with the delete key.
Right tool for the job is my motto. Don't hunt moscitos with torpedos. hey I am sure you could shave even more time if you used asm, I am sure your boss would love to see you do that.
> Right tool for the job is my motto. Don't hunt moscitos with
> torpedos. hey I am sure you could shave even more time if you
> used asm, I am sure your boss would love to see you do that.
There is no point in arguing with people who can never admit
the remote possibility that there is a better way of doing things.
Simply put, there are better ways to sort than with bubble sort.
End of story.
Your example is this:
I can remove a tire from my car with a tire iron, and it will work.
However, you cannot tell me that it'd be better than my air-
ratchet. This is simply not true. Sure, with both I have to remove
five lug nuts, so they're both doing the same thing; however
I obviously have the advantage over you if I'm using an air-
ratchet and you're stuck with a tire iron.
Quzah.
Hope is the first step on the road to disappointment.
There are plenty of ways that are better then bubble sort and that was only an easy suggestion from my side. Here are some other methods you can search for.
Bubble sort (well it's first in the book C++ Unleashed)
Insertion sort
Selection sort
Quick sort
Merge sort
Shell sort
Heap sort
Let me know if you want help with any one in particular.
>Bubble sort (well it's first in the book C++ Unleashed)
Actually, selection sort is the first in the Rapid Sorting Techniques chapter. Also, I do believe that after the introduction to bubble sort Dann says "Don't use bubble-sort. It's simply horrible."
-Prelude
My best code is written with the delete key.
Dann?? It is written by Jesse Liberty and there isn't any special chapter about rapid sorting
Indeed he does. I can't remember the exact quote, but words to that effect.
To say that Bubble sort is a good answer is like saying that "void main ()" would be a good way to define his programs primary function, since it works, and I guess, since it requires less typing on return functions, you might say it's easier. Patoohey.
Don't worry Prelude, casting perls before swine is just like a bubble sort, a waste of valuable resources.
where n is elements in arrayCode:Worst case Best case Bubble sort O(n2) O(n) Insertion sort O(n2) O(n) Selection sort O(n2) O(n2) Heap sort O(nlog2n) O(nlog2n) Merge sort O(nlog2n) O(nlog2n) Quik sort O(n2) O(nlog2n) Sheel sort O(n(log2n)2)
>Dann?? It is written by Jesse Liberty and there isn't any special chapter about rapid sorting
Chapter 13: Rapid Sorting Techniques, by Dann Corbit
We were talking about different books, I was thinking of C Unleashed, not C++ Unleashed. But my point still holds, bubble sort is lame and worthless.
-Prelude
My best code is written with the delete key.