Arrays alphabetical order?

#define ARRAYSIZE 18
String results[ARRAYSIZE] = { "Ben", "Bruno", "Natha", "Fabrice", "Jacques", "Alain", "Pierre", "Paul", "Luc", "Renault", "Beatrice", "Mathieu", "Claire", "Danielle", "Fabienne", "Gilbert",  "Henri"};

Hello how to classify these names in alphabetical order?
Thank you

Hello how to classify these names in alphabetical order?

I assume that you mean how can they be sorted into alphabetical order. Where should the sorted list be put ? Would it be good enough if an array of indices to the original array in alphabetical order was output ?

Yes, I want who classifies each name in alphabetical order

Have you tried a Google search for "sorting algorithms in C++" ?

Yes I did not find it done 2 hours

Two hours to sort that tiny list?

2 hours to try sorting the list, Sorry for my english, i'm french

qsort?

UKHeliBob: Have you tried a Google search for "sorting algorithms in C++" ?

Google for "bubble sort".

Paul

Yes i try to sort the arrays (alphabetical),

"bubble sort". ??????

I'm really sorry to tell you that because I know it's wasting time, but can you send me the code

Sure

Thank you <3

Apex142: Yes i try to sort the arrays (alphabetical),

"bubble sort". ??????

I'm really sorry to tell you that because I know it's wasting time, but can you send me the code

Before I wrote that, I used Google to search for bubble sort. The first entry returned was a very good description with an example of the logic.

I think a bubble sort was the first IBM 360 assembly code we had to write in class. Much easier in "C".

Paul

Not sure why bubble sort is the standard answer for first try at sorting algorithms. Inefficient, and minorly unintuitive. If you didn't know anything about sorting, and you had to come up with a sorting algorithm, would you come up with a bubble sort? Not me.

Insertion sort makes more sense. Plus, it's a lot more efficient.

Even selection sort makes more sense.

Just use qsort. No need to reinvent the wheel over and over again.

(If Arduino's flavor of C++ supports sort, you could use that instead.)

Edit: In any case, a Google search will give you a lot of ways to sort an array in C++.

Jimmus:
Not sure why bubble sort is the standard answer for first try at sorting algorithms. Inefficient, and minorly unintuitive. If you didn’t know anything about sorting, and you had to come up with a sorting algorithm, would you come up with a bubble sort? Not me.

Insertion sort makes more sense. Plus, it’s a lot more efficient.

Even selection sort makes more sense.

Nope.

All the sorting algorithms you mention are equally bad, O(n2) on average.

See Sorting_algorithm “Comparison of algorithms”.

That is true. Theoretically the big O notation is the same, and their computational complexity is the same. However, look at the main Bubble Sort page. Specifically the In practice section. There are other issues at play here.

On random lists, insertion sort is 5 times faster than bubble sort?

I don't know about that, but my experience with implementing all three of those sorting algorithms has been that insertion sort was easier to understand, easier to write, and significantly faster executing.

I know it's not really relevant, but when I pick up ten cards and want to sort them, I instinctively use an insertion sort. I really can't see myself running a bubble sort on them. I've done it as an exercise, but it just seemed ridiculous.

Apex142: ```

define ARRAYSIZE 18

String results[ARRAYSIZE] = { "Ben", "Bruno", "Natha", "Fabrice", "Jacques", "Alain", "Pierre", "Paul", "Luc", "Renault", "Beatrice", "Mathieu", "Claire", "Danielle", "Fabienne", "Gilbert",  "Henri"}; ```

Hello how to classify these names in alphabetical order? Thank you

Here ya go:

#define ARRAYSIZE 18
String results[ARRAYSIZE] = { 
  "Alain", 
  "Beatrice", 
  "Ben", 
  "Bruno", 
  "Claire", 
  "Danielle", 
  "Fabienne", 
  "Fabrice", 
  "Gilbert",  
  "Henri",
  "Jacques", 
  "Luc", 
  "Mathieu", 
  "Natha", 
  "Paul", 
  "Pierre", 
  "Renault"
};

Whandall:

Insertion sort makes more sense. Plus, it’s a lot more efficient.

Nope.

All the sorting algorithms you mention are equally bad, O(n2) on average.

If you use a binary chop search to find the insertion point, insertion sort takes O(n log n) comparisons. If comparisons are relatively expensive (eg: long strings mostly having similar prefixes; anything needing a database fetch) and the insertions are relatively efficient (eg: memmove and an array of pointers), it’s better than O(n2).

Picking a suitable sorting algorithm will always be more an art than a science, because performance depends on what is being sorted. Quicksort does poorly on lists in reverse order. Smoothsort does well on lists that are mostly already sorted; whereas heapsort in the same situation is inefficient, although otherwise its usually a good choice. Bubble sort is perfectly fine for small arrays, where the overhead is the code itself, but in this situation shellsort is a better choice (I like to use fibonnaci numbers, rather than simply dividing the shells by 2, because shellsort tends to works better where the shell sizes are relatively prime). Mergesort is appropriate for data on magnetic tape or things like magnetic tape.

etc, etc

PaulMurrayCbr:
Nope.

All the sorting algorithms you mention are equally bad, O(n2) on average.

If you use a binary chop search to find the insertion point, insertion sort takes O(n log n) comparisons. If comparisons are relatively expensive (eg: long strings mostly having similar prefixes; anything needing a database fetch) and the insertions are relatively efficient (eg: memmove and an array of pointers), it’s better than O(n2).

Picking a suitable sorting algorithm will always be more an art than a science, because performance depends on what is being sorted. Quicksort does poorly on lists in reverse order. Smoothsort does well on lists that are mostly already sorted; whereas heapsort in the same situation is inefficient, although otherwise its usually a good choice. Bubble sort is perfectly fine for small arrays, where the overhead is the code itself, but in this situation shellsort is a better choice (I like to use fibonnaci numbers, rather than simply dividing the shells by 2, because shellsort tends to works better where the shell sizes are relatively prime). Mergesort is appropriate for data on magnetic tape or things like magnetic tape.

etc, etc

maybe uploading to a Cray supercomputer would make it faster?

my gosh, OP’s sorting a small array, he could use chisanbop and do it efficiently.