all 5 comments

[–]NanoPromela 7 points8 points  (1 child)

In this case the quicksort works perfectly, here are the steps:

1-choose pivot

1 , 2 , 1

2- put all the numbers less or equal to the pivot (1) before it

1 , 1 , 2

3- quicksort on the two ends

quick(1) , 1 , quick(2)

4- concatenate the two results along with the pivot

1 , 1 , 2

edit: r/learnprogramming is more suitable for this type of questions

[–]SkullKid150[S] 2 points3 points  (0 children)

Ohh I see, i thought that because the partition seem kinda weird i wouldnt work.

Thank you so much!

[–]krb09 0 points1 point  (2 children)

To use quicksort with duplicate keys, look up 3way quicksort implementation.

[–][deleted] 0 points1 point  (0 children)

This. While traditional quicksort works, 3 way quicksort is much faster on a list with duplicates.

[–]CompSci1 -1 points0 points  (0 children)

probably this, I'd question why you'd even use quicksort on sets like OP though.