-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountcode.html
More file actions
87 lines (74 loc) · 1.72 KB
/
countcode.html
File metadata and controls
87 lines (74 loc) · 1.72 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<style>
body {padding-top:50px ; margin-top: auto; margin-left: 30px;background-color:#0c7b93;color: white}
h1 {text-align: center; color: black;}
</style>
</head>
<body>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<style>
body {padding-top:50px ; margin-top: auto; margin-left: 30px;}
h1 {text-align: center;}
</style>
</head>
<body>
<h1>COUNT SORT
<div class="">
<button onclick="location.href='index.html'">Go to Home Page</button> <br /><br />
</div></h1>
#include <iostream><br />
using namespace std;<br>
int k=0;<br>
void countSort(int A[],int B[],int n)
{<br>
int C[k];<br>
for(int i=0;i<k+1;i++)
{<br>
C[i]=0;
}<br>
for(int j=1;j<=n;j++)
{<br>
C[A[j]]++;
}<br>
for(int i=1;i<=k;i++)
{<br>
C[i]+=C[i-1];
}<br>
for(int j=n;j>=1;j--)
{<br>
B[C[A[j]]]=A[j]; <br>
C[A[j]]=C[A[j]]-1;
}<br>
}<br>
int main()
{<br>
int n;<br>
cout<<"Enter the size of the array :";<br>
cin>>n;<br>
int A[n],B[n];<br>
for(int i=1;i<=n;i++)
{<br>
cin>>A[i];<br>
if(A[i]>k)
{<br>
k=A[i];
}
}<br>
countSort(A,B,n);<br>
for(int i=1;i<=n;i++)
{<br>
cout < < B[i] < < " ";
}<br>
cout < < endl;<br>
return 0;<br>
}<br>
</body>
</html>