Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
controle-c-002
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
florian.burgener
controle-c-002
Commits
e76caac0
Commit
e76caac0
authored
3 years ago
by
florian.burgener
Browse files
Options
Downloads
Patches
Plain Diff
Validation ex2
parent
9e09c033
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ex2/ex2.c
+86
-2
86 additions, 2 deletions
ex2/ex2.c
with
86 additions
and
2 deletions
ex2/ex2.c
+
86
−
2
View file @
e76caac0
...
...
@@ -9,23 +9,35 @@
*
*/
#include
<math.h>
#include
<stdbool.h>
#include
<stdint.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
// LinkedListNode.h
typedef
struct
LinkedListNode
{
struct
LinkedListNode
*
next
;
int32_t
value
;
}
LinkedListNode
;
/**
* @brief Creation of a new node.
*
* @param value
* @return LinkedListNode*
*/
LinkedListNode
*
linked_list_node_new
(
int32_t
value
);
/**
* @brief Deletion of a node.
*
* @param node
*/
void
linked_list_node_delete
(
LinkedListNode
**
node
);
// LinkedListNode.c
LinkedListNode
*
linked_list_node_new
(
int32_t
value
)
{
LinkedListNode
*
node
=
(
LinkedListNode
*
)
malloc
(
sizeof
(
LinkedListNode
));
...
...
@@ -41,19 +53,85 @@ void linked_list_node_delete(LinkedListNode **node) {
}
// LinkedList.h
typedef
struct
{
LinkedListNode
*
root
;
}
LinkedList
;
/**
* @brief Creation of a new linked list.
*
* @return LinkedList*
*/
LinkedList
*
linked_list_new
();
/**
* @brief Deletion of the linked list.
*
* @param list
*/
void
linked_list_delete
(
LinkedList
**
list
);
/**
* @brief Count the number of nodes in the list.
*
* @param list
* @return int32_t
*/
int32_t
linked_list_count
(
LinkedList
*
list
);
/**
* @brief Checks if the list is empty or not.
*
* @param list
* @return true
* @return false
*/
bool
linked_list_is_empty
(
LinkedList
*
list
);
/**
* @brief Adds a value at the end of the list.
*
* @param list
* @param value
* @return LinkedListNode*
*/
LinkedListNode
*
linked_list_add_last
(
LinkedList
*
list
,
int32_t
value
);
/**
* @brief Removes a node from the list.
*
* @param list
* @param node
*/
void
linked_list_remove
(
LinkedList
*
list
,
LinkedListNode
**
node
);
/**
* @brief Displays the list.
*
* @param list
*/
void
linked_list_print
(
LinkedList
*
list
);
/**
* @brief Inserts a value at the desired index, if the index does not exist does nothing.
*
* @param list
* @param index
* @param value
*/
void
linked_list_insert_at_index
(
LinkedList
*
list
,
int32_t
index
,
int32_t
value
);
/**
* @brief Deletes a node at the desired index, if the index does not exist does nothing.
*
* @param list
* @param index
*/
void
linked_list_remove_at_index
(
LinkedList
*
list
,
int32_t
index
);
// LinkedList.c
LinkedList
*
linked_list_new
()
{
LinkedList
*
list
=
(
LinkedList
*
)
malloc
(
sizeof
(
LinkedList
));
...
...
@@ -180,15 +258,18 @@ int main() {
int32_t
values_length
=
4
;
int32_t
values
[
values_length
];
// Reading of the 4 input values to be added to the list.
for
(
int32_t
i
=
0
;
i
<
values_length
;
i
+=
1
)
{
int32_t
value
;
scanf
(
"%d"
,
&
value
);
values
[
i
]
=
value
;
}
// Reading of the index where the value 0 must be inserted.
int32_t
insert_index
;
scanf
(
"%d"
,
&
insert_index
);
// Reading of the index where the value must be removed.
int32_t
remove_index
;
scanf
(
"%d"
,
&
remove_index
);
...
...
@@ -196,13 +277,16 @@ int main() {
LinkedList
*
list
=
linked_list_new
();
// Addition of the 4 numbers read as input in the list.
for
(
int32_t
i
=
4
-
1
;
i
>=
0
;
i
-=
1
)
{
linked_list_add_last
(
list
,
values
[
i
]);
}
// Insertion of the number 0 at the index specified in input.
linked_list_insert_at_index
(
list
,
insert_index
,
0
);
linked_list_print
(
list
);
// Deletion of the value at the index read in input.
linked_list_remove_at_index
(
list
,
remove_index
);
linked_list_print
(
list
);
...
...
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