Sort an array of 0s 1s and 2s
Given an array which include 3 types of integer numbers (0,1,2). Our goal is to sort this array in ascending order. For example.
Example A
// Befor sort
arr[] = [0, 1, 0, 2, 2, 1, 2,0, 0, 2, 0, 1, 1, 0 ,2]
// After sort
arr[] = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2]
Example B
// Befor sort
arr[] = [1,2,0,0,1]
// After sort
arr[] = [0, 0, 1, 1, 2]
Solution by using counting
-
1) Sort an array of 0s 1s and 2s in java
2) Sort an array of 0s 1s and 2s in c++
3) Sort an array of 0s 1s and 2s in c
4) Sort an array of 0s 1s and 2s in c#
5) Sort an array of 0s 1s and 2s in php
6) Sort an array of 0s 1s and 2s in node js
7) Sort an list of 0s 1s and 2s in python
8) Sort an array of 0s 1s and 2s in ruby
9) Sort an array of 0s 1s and 2s in scala
10) Sort an array of 0s 1s and 2s in swift
11) Sort an array of 0s 1s and 2s in kotlin
12) Sort an array of 0s 1s and 2s in golang
13) Sort an array of 0s 1s and 2s in vb.net
14) Sort an array of 0s 1s and 2s in typescript
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment