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
1a483060
Commit
1a483060
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add sort with insertion
The program now perform a descending sort using the insertion algorithm.
parent
4dc6ea86
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
histo.c
+6
-1
6 additions, 1 deletion
histo.c
unidimensional_array.c
+13
-0
13 additions, 0 deletions
unidimensional_array.c
unidimensional_array.h
+2
-0
2 additions, 0 deletions
unidimensional_array.h
with
21 additions
and
1 deletion
histo.c
+
6
−
1
View file @
1a483060
...
...
@@ -31,7 +31,12 @@ int main() {
// Permute smallest value with the last value
permute_lowest_value_with_last_value
(
array
,
array_size
);
printf
(
"Array after swapping the smallest value with the last one
\n
"
);
printf
(
"Array after swapping the smallest value with the last one :
\n
"
);
print_array
(
array
,
array_size
);
// Descending sort the array by using the insertion algorithm
sort_by_insertion_desc
(
array
,
array_size
);
printf
(
"Array after insertion desc sort :
\n
"
);
print_array
(
array
,
array_size
);
// Swap the highest value of the array with the last element of the array
...
...
This diff is collapsed.
Click to expand it.
unidimensional_array.c
+
13
−
0
View file @
1a483060
...
...
@@ -84,6 +84,19 @@ void permute_lowest_value_with_last_value(int* array, size_t array_size) {
swap
(
&
array
[
lowest_index
],
&
array
[
last_index
]);
}
void
sort_by_insertion_desc
(
int
*
array
,
size_t
array_size
)
{
size_t
i
=
1
;
while
(
i
<
array_size
)
{
size_t
k
=
i
;
while
(
k
>
0
&&
array
[
k
-
1
]
<
array
[
k
])
{
swap
(
&
array
[
k
],
&
array
[
k
-
1
]);
k
-=
1
;
}
i
++
;
}
}
int
find_index_highest_value_in_array
(
int
*
array
,
size_t
array_size
)
{
int
highest_value
;
size_t
index_highest_value
=
0
;
...
...
This diff is collapsed.
Click to expand it.
unidimensional_array.h
+
2
−
0
View file @
1a483060
...
...
@@ -21,6 +21,8 @@ void shuffle_array(int* array, size_t array_size);
void
perform_cyclic_permutation
(
int
*
array
,
size_t
array_size
,
size_t
cycle_number
);
void
sort_by_insertion_desc
(
int
*
array
,
size_t
array_size
);
void
print_array
(
int
*
array
,
size_t
array_size
);
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