Sort an array of zeros, ones and twos in linear time complexity
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Algorithm
Swap (array [low], array [mid]) since 0's should be at starting
Increment low
Increment mid
Break statement
Keep as it is since 1's should be at middle after being sorted
Increment mid
Break statement
Swap (array [mid], array [high])
Decrement high
Break statement
C++ program to sort an array of 0's, 1's and 2's in linear time complexity
Output
need an explanation for this answer? contact us directly to get an explanation for this answer