-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoloursort.cpp
More file actions
51 lines (51 loc) · 992 Bytes
/
coloursort.cpp
File metadata and controls
51 lines (51 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
using namespace std;
int main()
{
cout<<"This program is prepared by JHIL 22CE009\n"<<endl;
int a[50];
int cnt1=0,cnt2=0,cnt3=0;
int size;
cout<<"Enter the size of colours in an array : ";
cin>>size;
cout<<"Enter 0 for red colour"<<endl;
cout<<"Enter 1 for white colour"<<endl;
cout<<"Enter 2 for blue colour"<<endl;
for(int i=0;i<size;i++)
{
cout<<"colour["<<i<<"]:";
cin>>a[i];
}
for(int i=0;i<size;i++)
{
if(a[i]==0)
{
cnt1++;
}
if(a[i]==1)
{
cnt2++;
}
if(a[i]==2)
{
cnt3++;
}
}
for(int i=0;i<cnt1;i++)
{
a[i]=0;
}
for(int i=cnt1;i<cnt2+cnt1;i++)
{
a[i]=1;
}
for(int i=cnt1+cnt2;i<size;i++)
{
a[i]=2;
}
cout<<"Sorted colours "<<endl;
for(int i=0;i<size;i++)
{
cout<<"colour["<<i<<"]:"<<a[i]<<endl;
}
}