Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISC 142 - Travail Pratique 011
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
ISC 142 - Travail Pratique 011
Commits
6d45ad9a
Commit
6d45ad9a
authored
3 years ago
by
florian.burgener
Browse files
Options
Downloads
Patches
Plain Diff
Fix LF
parent
e6ea047a
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+23
-23
23 additions, 23 deletions
Makefile
circ_list.c
+126
-126
126 additions, 126 deletions
circ_list.c
circ_list.h
+22
-22
22 additions, 22 deletions
circ_list.h
circ_list_tests.c
+101
-101
101 additions, 101 deletions
circ_list_tests.c
with
272 additions
and
272 deletions
Makefile
+
23
−
23
View file @
6d45ad9a
CC
=
gcc
CC
=
gcc
CCFLAGS
=
-g
-Wall
-Wextra
-pedantic
-fsanitize
=
address
-fsanitize
=
leak
CCFLAGS
=
-g
-Wall
-Wextra
-pedantic
-fsanitize
=
address
-fsanitize
=
leak
circ_list.o
:
circ_list.c circ_list.h
circ_list.o
:
circ_list.c circ_list.h
$(
CC
)
$(
CCFLAGS
)
-c
$<
-o
$@
$(
CC
)
$(
CCFLAGS
)
-c
$<
-o
$@
joseph.o
:
joseph.c
joseph.o
:
joseph.c
$(
CC
)
$(
CCFLAGS
)
-c
$<
-o
$@
$(
CC
)
$(
CCFLAGS
)
-c
$<
-o
$@
joseph
:
joseph.o circ_list.o
joseph
:
joseph.o circ_list.o
$(
CC
)
$(
CCFLAGS
)
-o
joseph joseph.o circ_list.o
$(
CC
)
$(
CCFLAGS
)
-o
joseph joseph.o circ_list.o
pointer_sort
:
pointer_sort.o
pointer_sort
:
pointer_sort.o
$(
CC
)
$(
CCFLAGS
)
-o
pointer_sort pointer_sort.o
$(
CC
)
$(
CCFLAGS
)
-o
pointer_sort pointer_sort.o
circ_list_tests.o
:
circ_list_tests.c
circ_list_tests.o
:
circ_list_tests.c
$(
CC
)
$(
CCFLAGS
)
-c
$<
-o
$@
$(
CC
)
$(
CCFLAGS
)
-c
$<
-o
$@
circ_list_tests
:
circ_list_tests.o circ_list.o
circ_list_tests
:
circ_list_tests.o circ_list.o
$(
CC
)
$(
CCFLAGS
)
-o
circ_list_tests circ_list_tests.o circ_list.o
$(
CC
)
$(
CCFLAGS
)
-o
circ_list_tests circ_list_tests.o circ_list.o
clean
:
clean
:
rm
-f
*
.o joseph pointer_sort circ_list_tests
rm
-f
*
.o joseph pointer_sort circ_list_tests
This diff is collapsed.
Click to expand it.
circ_list.c
+
126
−
126
View file @
6d45ad9a
#include
"circ_list.h"
#include
"circ_list.h"
#include
<stdlib.h>
#include
<stdlib.h>
element
*
list_create
()
{
element
*
list_create
()
{
return
NULL
;
return
NULL
;
}
}
bool
list_empty
(
element
*
head
)
{
bool
list_empty
(
element
*
head
)
{
return
head
==
NULL
;
return
head
==
NULL
;
}
}
unsigned
int
list_count
(
element
*
head
)
{
unsigned
int
list_count
(
element
*
head
)
{
if
(
list_empty
(
head
))
{
if
(
list_empty
(
head
))
{
return
0
;
return
0
;
}
}
unsigned
int
count
=
0
;
unsigned
int
count
=
0
;
element
*
iterator
=
head
;
element
*
iterator
=
head
;
do
{
do
{
count
+=
1
;
count
+=
1
;
iterator
=
iterator
->
next
;
iterator
=
iterator
->
next
;
}
while
(
iterator
!=
head
);
}
while
(
iterator
!=
head
);
return
count
;
return
count
;
}
}
element
*
list_move
(
element
*
head
)
{
element
*
list_move
(
element
*
head
)
{
if
(
list_empty
(
head
))
{
if
(
list_empty
(
head
))
{
return
NULL
;
return
NULL
;
}
}
return
head
->
next
;
return
head
->
next
;
}
}
element
*
list_insert_after
(
element
*
head
,
int
data
)
{
element
*
list_insert_after
(
element
*
head
,
int
data
)
{
element
*
new_element
=
(
element
*
)
malloc
(
sizeof
(
element
));
element
*
new_element
=
(
element
*
)
malloc
(
sizeof
(
element
));
new_element
->
data
=
data
;
new_element
->
data
=
data
;
if
(
list_empty
(
head
))
{
if
(
list_empty
(
head
))
{
new_element
->
next
=
new_element
;
new_element
->
next
=
new_element
;
}
else
{
}
else
{
new_element
->
next
=
head
->
next
;
new_element
->
next
=
head
->
next
;
head
->
next
=
new_element
;
head
->
next
=
new_element
;
}
}
return
new_element
;
return
new_element
;
}
}
element
*
list_insert_before
(
element
*
head
,
int
data
)
{
element
*
list_insert_before
(
element
*
head
,
int
data
)
{
if
(
list_empty
(
head
))
{
if
(
list_empty
(
head
))
{
return
list_insert_after
(
head
,
data
);
return
list_insert_after
(
head
,
data
);
}
}
element
*
iterator
=
head
;
element
*
iterator
=
head
;
while
(
iterator
->
next
!=
head
)
{
while
(
iterator
->
next
!=
head
)
{
iterator
=
iterator
->
next
;
iterator
=
iterator
->
next
;
}
}
return
list_insert_after
(
iterator
,
data
);
return
list_insert_after
(
iterator
,
data
);
}
}
element
*
list_search
(
element
*
head
,
int
data
)
{
element
*
list_search
(
element
*
head
,
int
data
)
{
if
(
list_empty
(
head
))
{
if
(
list_empty
(
head
))
{
return
NULL
;
return
NULL
;
}
}
element
*
iterator
=
head
;
element
*
iterator
=
head
;
do
{
do
{
if
(
iterator
->
data
==
data
)
{
if
(
iterator
->
data
==
data
)
{
return
iterator
;
return
iterator
;
}
}
iterator
=
iterator
->
next
;
iterator
=
iterator
->
next
;
}
while
(
iterator
!=
head
);
}
while
(
iterator
!=
head
);
return
NULL
;
return
NULL
;
}
}
// This function cannot work when the element to be removed is the head.
// This function cannot work when the element to be removed is the head.
element
*
list_remove
(
element
*
head
,
int
data
)
{
element
*
list_remove
(
element
*
head
,
int
data
)
{
element
*
el
=
list_search
(
head
,
data
);
element
*
el
=
list_search
(
head
,
data
);
if
(
el
==
NULL
)
{
if
(
el
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
element
*
iterator
=
head
;
element
*
iterator
=
head
;
while
(
iterator
->
next
!=
el
)
{
while
(
iterator
->
next
!=
el
)
{
iterator
=
iterator
->
next
;
iterator
=
iterator
->
next
;
}
}
iterator
->
next
=
iterator
->
next
->
next
;
iterator
->
next
=
iterator
->
next
->
next
;
return
el
;
return
el
;
}
}
void
list_free
(
element
*
head
)
{
void
list_free
(
element
*
head
)
{
if
(
list_empty
(
head
))
{
if
(
list_empty
(
head
))
{
return
;
return
;
}
}
element
*
iterator
=
head
;
element
*
iterator
=
head
;
do
{
do
{
element
*
tmp
=
iterator
;
element
*
tmp
=
iterator
;
iterator
=
iterator
->
next
;
iterator
=
iterator
->
next
;
free
(
tmp
);
free
(
tmp
);
}
while
(
iterator
!=
head
);
}
while
(
iterator
!=
head
);
}
}
void
list_process
(
element
*
head
,
int
(
*
action
)(
int
))
{
void
list_process
(
element
*
head
,
int
(
*
action
)(
int
))
{
if
(
list_empty
(
head
))
{
if
(
list_empty
(
head
))
{
return
;
return
;
}
}
element
*
iterator
=
head
;
element
*
iterator
=
head
;
do
{
do
{
iterator
->
data
=
action
(
iterator
->
data
);
iterator
->
data
=
action
(
iterator
->
data
);
iterator
=
iterator
->
next
;
iterator
=
iterator
->
next
;
}
while
(
iterator
!=
head
);
}
while
(
iterator
!=
head
);
}
}
This diff is collapsed.
Click to expand it.
circ_list.h
+
22
−
22
View file @
6d45ad9a
#ifndef CIRC_LIST_H
#ifndef CIRC_LIST_H
#define CIRC_LIST_H
#define CIRC_LIST_H
#include
<stdbool.h>
#include
<stdbool.h>
typedef
struct
element
{
typedef
struct
element
{
int
data
;
int
data
;
struct
element
*
next
;
struct
element
*
next
;
}
element
;
}
element
;
element
*
list_create
();
element
*
list_create
();
bool
list_empty
(
element
*
head
);
bool
list_empty
(
element
*
head
);
unsigned
int
list_count
(
element
*
head
);
unsigned
int
list_count
(
element
*
head
);
element
*
list_move
(
element
*
head
);
element
*
list_move
(
element
*
head
);
element
*
list_insert_after
(
element
*
head
,
int
data
);
element
*
list_insert_after
(
element
*
head
,
int
data
);
element
*
list_insert_before
(
element
*
head
,
int
data
);
element
*
list_insert_before
(
element
*
head
,
int
data
);
element
*
list_search
(
element
*
head
,
int
data
);
element
*
list_search
(
element
*
head
,
int
data
);
element
*
list_remove
(
element
*
head
,
int
data
);
element
*
list_remove
(
element
*
head
,
int
data
);
void
list_free
(
element
*
head
);
void
list_free
(
element
*
head
);
void
list_process
(
element
*
head
,
int
(
*
action
)(
int
));
void
list_process
(
element
*
head
,
int
(
*
action
)(
int
));
#endif
#endif
This diff is collapsed.
Click to expand it.
circ_list_tests.c
+
101
−
101
View file @
6d45ad9a
#include
<assert.h>
#include
<assert.h>
#include
<stdint.h>
#include
<stdint.h>
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
"circ_list.h"
#include
"circ_list.h"
int
action_add_10
(
int
element
)
{
int
action_add_10
(
int
element
)
{
return
element
+
10
;
return
element
+
10
;
}
}
void
print_list
(
element
*
list
)
{
void
print_list
(
element
*
list
)
{
element
*
iterator
=
list
;
element
*
iterator
=
list
;
do
{
do
{
printf
(
"%d "
,
iterator
->
data
);
printf
(
"%d "
,
iterator
->
data
);
iterator
=
iterator
->
next
;
iterator
=
iterator
->
next
;
}
while
(
iterator
!=
list
);
}
while
(
iterator
!=
list
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
int
main
()
{
int
main
()
{
// list_create
// list_create
element
*
list
=
list_create
();
element
*
list
=
list_create
();
assert
(
list
==
NULL
);
assert
(
list
==
NULL
);
// list_insert_after
// list_insert_after
printf
(
"list_insert_after
\n
"
);
printf
(
"list_insert_after
\n
"
);
list
=
list_insert_after
(
list
,
1
);
list
=
list_insert_after
(
list
,
1
);
assert
(
list
->
data
==
1
);
assert
(
list
->
data
==
1
);
print_list
(
list
);
print_list
(
list
);
list
=
list_insert_after
(
list
,
3
);
list
=
list_insert_after
(
list
,
3
);
assert
(
list
->
data
==
3
);
assert
(
list
->
data
==
3
);
assert
(
list
->
next
->
data
==
1
);
assert
(
list
->
next
->
data
==
1
);
assert
(
list
->
next
->
next
->
data
==
3
);
assert
(
list
->
next
->
next
->
data
==
3
);
print_list
(
list
);
print_list
(
list
);
list
=
list_insert_before
(
list
,
2
);
list
=
list_insert_before
(
list
,
2
);
printf
(
"list_insert_before
\n
"
);
printf
(
"list_insert_before
\n
"
);
assert
(
list
->
data
==
2
);
assert
(
list
->
data
==
2
);
assert
(
list
->
next
->
data
==
3
);
assert
(
list
->
next
->
data
==
3
);
assert
(
list
->
next
->
next
->
data
==
1
);
assert
(
list
->
next
->
next
->
data
==
1
);
assert
(
list
->
next
->
next
->
next
->
data
==
2
);
assert
(
list
->
next
->
next
->
next
->
data
==
2
);
print_list
(
list
);
print_list
(
list
);
// list_empty
// list_empty
element
*
empty_list
=
list_create
();
element
*
empty_list
=
list_create
();
assert
(
list_empty
(
empty_list
)
==
true
);
assert
(
list_empty
(
empty_list
)
==
true
);
assert
(
list_empty
(
list
)
==
false
);
assert
(
list_empty
(
list
)
==
false
);
// list_count
// list_count
assert
(
list_count
(
empty_list
)
==
0
);
assert
(
list_count
(
empty_list
)
==
0
);
assert
(
list_count
(
list
)
==
3
);
assert
(
list_count
(
list
)
==
3
);
// list_search
// list_search
element
*
search_result_1
=
list_search
(
list
,
1
);
element
*
search_result_1
=
list_search
(
list
,
1
);
assert
(
search_result_1
->
data
==
1
);
assert
(
search_result_1
->
data
==
1
);
element
*
search_result_2
=
list_search
(
list
,
4
);
element
*
search_result_2
=
list_search
(
list
,
4
);
assert
(
search_result_2
==
NULL
);
assert
(
search_result_2
==
NULL
);
// list_process
// list_process
printf
(
"list_process
\n
"
);
printf
(
"list_process
\n
"
);
list_process
(
list
,
action_add_10
);
list_process
(
list
,
action_add_10
);
assert
(
list
->
data
==
12
);
assert
(
list
->
data
==
12
);
assert
(
list
->
next
->
data
==
13
);
assert
(
list
->
next
->
data
==
13
);
assert
(
list
->
next
->
next
->
data
==
11
);
assert
(
list
->
next
->
next
->
data
==
11
);
assert
(
list
->
next
->
next
->
next
->
data
==
12
);
assert
(
list
->
next
->
next
->
next
->
data
==
12
);
print_list
(
list
);
print_list
(
list
);
// list_remove
// list_remove
printf
(
"list_remove
\n
"
);
printf
(
"list_remove
\n
"
);
element
*
removed_element_1
=
list_remove
(
list
,
13
);
element
*
removed_element_1
=
list_remove
(
list
,
13
);
assert
(
removed_element_1
->
data
==
13
);
assert
(
removed_element_1
->
data
==
13
);
assert
(
list
->
data
==
12
);
assert
(
list
->
data
==
12
);
assert
(
list
->
next
->
data
==
11
);
assert
(
list
->
next
->
data
==
11
);
assert
(
list
->
next
->
next
->
data
==
12
);
assert
(
list
->
next
->
next
->
data
==
12
);
free
(
removed_element_1
);
free
(
removed_element_1
);
print_list
(
list
);
print_list
(
list
);
// list_move
// list_move
printf
(
"list_move
\n
"
);
printf
(
"list_move
\n
"
);
list
=
list_move
(
list
);
list
=
list_move
(
list
);
assert
(
list
->
data
==
11
);
assert
(
list
->
data
==
11
);
assert
(
list
->
next
->
data
==
12
);
assert
(
list
->
next
->
data
==
12
);
assert
(
list
->
next
->
next
->
data
==
11
);
assert
(
list
->
next
->
next
->
data
==
11
);
print_list
(
list
);
print_list
(
list
);
list
=
list_move
(
list
);
list
=
list_move
(
list
);
assert
(
list
->
data
==
12
);
assert
(
list
->
data
==
12
);
assert
(
list
->
next
->
data
==
11
);
assert
(
list
->
next
->
data
==
11
);
assert
(
list
->
next
->
next
->
data
==
12
);
assert
(
list
->
next
->
next
->
data
==
12
);
print_list
(
list
);
print_list
(
list
);
// list_free
// list_free
list_free
(
list
);
list_free
(
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