-6

I know stackoverflow has many questions like this one, but it appears that none of them are actually a solution to this.

I had a coding interview three weeks ago and one of the questions been "How do you sort an array of n people by their name in an alphabetical order ?" problem is not the answer, but Array.Sort() function was not allowed.

First thing that came in my mind was creating an array of chars of which i i can attempt to get the first char of each string from that array and store them in char[], then a nested loop to actually do the job, but after a few minutes passed this has no sense and it was or i think a wrong approach by me.

Looking in the Internet the algo that i am looking for is the Quicksort method, but this totally looks something overcomplicated, do i actually need to learn about Quicksort and replicate the algo myself or there is something less complicated that orders that array of people alphabetically ?

theo
  • 11
  • 2
  • 2
    The _practical_ solution is not to worry about the algorithm and use Linq's `.Sort()` method. Is there something more specific you need than [this](https://stackoverflow.com/questions/6965337/sort-a-list-alphabetically)? – gunr2171 Feb 15 '22 at 22:18
  • Exchange sort and bubble sort are really simple, if you need something you can write on the fly – Nigel Feb 15 '22 at 22:39
  • @NigelBess oh .... exactly what i was looking for... thank you.. i will now never forget about the bubble sort, ironically i was using it to sort integers too – theo Feb 15 '22 at 23:04
  • @theo Im glad that helped you out. I re-posted my comment as an answer to farm some sweet reputation points. Dont forget to upvote and select a best answer ;) – Nigel Feb 15 '22 at 23:32

1 Answers1

0

Exchange Sort and Bubble Sort are two quite simple sorting algorithms that can be written on the fly.

Nigel
  • 2,961
  • 1
  • 14
  • 32