FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
dataStructures/Array/AJugglingAlgorithm.CPP at master · Gobi19/dataStructures · GitHub
Gobi19
/
dataStructures
Public
forked from
darakian/dataStructures
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
dataStructures
/
Array
/
AJugglingAlgorithm.CPP
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (51 loc) · 704 Bytes
Breadcrumbs
dataStructures
/
Array
/
AJugglingAlgorithm.CPP
Copy path
File metadata and controls
56 lines (51 loc) · 704 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
iostream
>
#
include
<
conio
>
int
gcd
(
int
a,
int
b)
{
if
(b==
0
)
return
a;
else
return
gcd
(b, a%b);
}
void
ArrayRotate
(
int
A[],
int
n,
int
k)
{
int
d=-
1
,i,temp,j;
for
(i=
0
;i<
gcd
(n,k);i++)
{
j=i;
temp=A[i];
while
(
1
)
{
d=(j+k)%n;
if
(d==i)
break
;
A[j]=A[d];
j=d;
}
A[j]=temp;
}
}
void
displayArray
(
int
A[],
int
n)
{
int
i;
for
(i=
0
;i<n;i++)
cout<<A[i]<<
"
"
;
cout<<
"
\n
"
;
}
int
main
()
{
int
n,i,k;
cout<<
"
Enter size of the Array
\n
"
;
cin>>n;
int
A[
10
];
cout<<
"
Enter Array elements
\n
"
;
for
(i=
0
;i<n;i++)
cin>>A[i];
cout<<
"
Enter the value of k
\n
"
;
cin>>k;
displayArray
(A,n);
ArrayRotate
(A,n,k);
displayArray
(A,n);
getch
();
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL