Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
progseq-dynamic_memory_allocation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
dario.genga
progseq-dynamic_memory_allocation
Commits
9ae7a8d6
Commit
9ae7a8d6
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add cyclic permutation
Also edited the print_array method to allow more clarity to the display.
parent
5e54fe46
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
histo.c
+12
-0
12 additions, 0 deletions
histo.c
unidimensional_array.c
+17
-1
17 additions, 1 deletion
unidimensional_array.c
unidimensional_array.h
+2
-0
2 additions, 0 deletions
unidimensional_array.h
with
31 additions
and
1 deletion
histo.c
+
12
−
0
View file @
9ae7a8d6
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
int
main
()
{
int
main
()
{
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
size_t
cycle_number
=
3
;
// Ask the user the size of the array
// Ask the user the size of the array
size_t
array_size
=
ask_array_size
();
size_t
array_size
=
ask_array_size
();
int
*
array
=
malloc
(
array_size
*
sizeof
(
int
));
int
*
array
=
malloc
(
array_size
*
sizeof
(
int
));
...
@@ -15,6 +16,17 @@ int main() {
...
@@ -15,6 +16,17 @@ int main() {
fill_array_with_random_values
(
array
,
array_size
);
fill_array_with_random_values
(
array
,
array_size
);
// Print the array
// Print the array
printf
(
"Original array :
\n
"
);
print_array
(
array
,
array_size
);
// Shuffle the array
shuffle_array
(
array
,
array_size
);
printf
(
"Array after shuffle :
\n
"
);
print_array
(
array
,
array_size
);
// Perform a cyclic permutation
perform_cyclic_permutation
(
array
,
array_size
,
cycle_number
);
printf
(
"Array after cyclic permutation :
\n
"
);
print_array
(
array
,
array_size
);
print_array
(
array
,
array_size
);
// Find the lowest value in the array
// Find the lowest value in the array
...
...
This diff is collapsed.
Click to expand it.
unidimensional_array.c
+
17
−
1
View file @
9ae7a8d6
...
@@ -34,8 +34,24 @@ void fill_array_with_random_values(int* array, size_t array_size) {
...
@@ -34,8 +34,24 @@ void fill_array_with_random_values(int* array, size_t array_size) {
shuffle_array
(
array
,
array_size
);
shuffle_array
(
array
,
array_size
);
}
}
void
perform_cyclic_permutation
(
int
*
array
,
size_t
array_size
,
size_t
cycle_number
)
{
int
*
array_tmp
=
malloc
(
array_size
*
sizeof
(
int
));
for
(
size_t
i
=
0
;
i
<
array_size
;
i
++
)
{
size_t
tmp_index
=
(
i
+
cycle_number
)
%
array_size
;
array_tmp
[
tmp_index
]
=
array
[
i
];
}
for
(
size_t
i
=
0
;
i
<
array_size
;
i
++
)
{
array
[
i
]
=
array_tmp
[
i
];
}
free
(
array_tmp
);
}
void
print_array
(
int
*
array
,
size_t
array_size
)
{
void
print_array
(
int
*
array
,
size_t
array_size
)
{
printf
(
"
Array :
\n
["
);
printf
(
"["
);
for
(
size_t
i
=
0
;
i
<
array_size
;
i
++
)
for
(
size_t
i
=
0
;
i
<
array_size
;
i
++
)
{
{
printf
(
"%d"
,
array
[
i
]);
printf
(
"%d"
,
array
[
i
]);
...
...
This diff is collapsed.
Click to expand it.
unidimensional_array.h
+
2
−
0
View file @
9ae7a8d6
...
@@ -17,6 +17,8 @@ int find_index_highest_value_in_array(int* array, size_t array_size);
...
@@ -17,6 +17,8 @@ int find_index_highest_value_in_array(int* array, size_t array_size);
void
shuffle_array
(
int
*
array
,
size_t
array_size
);
void
shuffle_array
(
int
*
array
,
size_t
array_size
);
void
perform_cyclic_permutation
(
int
*
array
,
size_t
array_size
,
size_t
cycle_number
);
void
print_array
(
int
*
array
,
size_t
array_size
);
void
print_array
(
int
*
array
,
size_t
array_size
);
void
swap
(
int
*
x
,
int
*
y
);
void
swap
(
int
*
x
,
int
*
y
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment