Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stack
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
Show more breadcrumbs
algorithmique
lib_2021_malaspinas
stack
Commits
18d33345
Verified
Commit
18d33345
authored
3 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
fixed makefile, main compilation and test compilation
parent
4ee8a912
No related branches found
No related tags found
1 merge request
!3
Resolve "add makefile with structure"
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+9
-5
9 additions, 5 deletions
Makefile
main.c
+4
-3
4 additions, 3 deletions
main.c
stack.c
+32
-34
32 additions, 34 deletions
stack.c
stack_test.c
+3
-2
3 additions, 2 deletions
stack_test.c
with
48 additions
and
44 deletions
Makefile
+
9
−
5
View file @
18d33345
CC
:=
gcc
CC
:=
gcc
CFLAGS
:=
-g
-Wextra
-pedantic
-fsanitize
=
address
CFLAGS
:=
-g
-Wall
-Wextra
-pedantic
-fsanitize
=
address
LDFLGS
:=
-fsanitize
=
address
NAME
:=
stack
NAME
:=
stack
$(NAME)
:
main.o $(NAME).o
$(NAME)
:
main.o $(NAME).o
$(CC)
$(CFLAGS)
-o
$@
$^
-lSDL2
$(
CC
)
$(
CFLAGS
)
-o
$@
$^
$(
LDFLAGS
)
tests
:
$(NAME)_tests.o $(NAME).o
test
:
$(NAME)_test.o $(NAME).o
$(CC)
$(CFLAGS)
-o
$@
$^
$(
CC
)
$(
CFLAGS
)
-o
$@
$^
./test
$(NAME).o
:
$(NAME).h
$(NAME).o
:
$(NAME).h
.PHONY
:
clean
clean
:
clean
:
rm
-f
*.o
$(NAME)
tests
rm
-f
*
.o
$(
NAME
)
tests
This diff is collapsed.
Click to expand it.
main.c
+
4
−
3
View file @
18d33345
#include
"stack.h"
#include
<stdio.h>
#include
<stdio.h>
#include
"../include/stack
.h
"
#include
<stdlib
.h
>
int
main
(
void
)
{
int
main
(
void
)
{
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
stack.c
+
32
−
34
View file @
18d33345
#include
"stack.h"
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
"stack.h"
#define DEFAULT_CAPACITY 4
#define DEFAULT_CAPACITY 4
void
stack_init
(
stack
*
s
)
void
stack_init
(
stack
*
s
)
{
{
s
->
top
=
-
1
;
s
->
top
=
-
1
;
s
->
capacity
=
DEFAULT_CAPACITY
;
s
->
capacity
=
DEFAULT_CAPACITY
;
s
->
data
=
malloc
(
sizeof
(
int
)
*
DEFAULT_CAPACITY
);
s
->
data
=
malloc
(
sizeof
(
int
)
*
DEFAULT_CAPACITY
);
}
}
void
stack_destroy
(
stack
*
s
){
void
stack_destroy
(
stack
*
s
)
{
free
(
s
->
data
);
free
(
s
->
data
);
s
->
data
=
NULL
;
s
->
data
=
NULL
;
s
->
capacity
=
-
1
;
s
->
capacity
=
-
1
;
s
->
top
=
-
1
;
s
->
top
=
-
1
;
}
}
void
stack_pop
(
stack
*
s
,
int
*
value
){
void
stack_pop
(
stack
*
s
,
int
*
value
)
{
if
(
stack_is_empty
(
*
s
))
{
if
(
stack_is_empty
(
*
s
))
{
return
;
return
;
}
}
if
(
s
->
top
==
s
->
capacity
/
4
){
if
(
s
->
top
==
s
->
capacity
/
4
)
{
s
->
capacity
/=
2
;
s
->
capacity
/=
2
;
s
->
data
=
realloc
(
s
->
data
,
sizeof
(
int
)
*
s
->
capacity
);
s
->
data
=
realloc
(
s
->
data
,
sizeof
(
int
)
*
s
->
capacity
);
}
}
*
value
=
s
->
data
[
s
->
top
];
*
value
=
s
->
data
[
s
->
top
];
s
->
top
-=
1
;
s
->
top
-=
1
;
}
}
void
stack_peek
(
stack
s
,
int
*
value
){
void
stack_peek
(
stack
s
,
int
*
value
)
{
if
(
!
stack_is_empty
(
s
))
{
if
(
!
stack_is_empty
(
s
))
{
*
value
=
s
.
data
[
s
.
top
];
*
value
=
s
.
data
[
s
.
top
];
}
}
}
}
void
stack_print
(
const
stack
s
)
{
void
stack_print
(
const
stack
s
)
{
//TODO: replace if statement with following as soon as relevant function is
implemented
//
TODO: replace if statement with following as soon as relevant function is
//
if (!stack_is_empty()) {
// implemented
if (!stack_is_empty()) {
if
(
s
.
top
>=
0
)
{
if
(
s
.
top
>=
0
)
{
printf
(
" TOP
\n
--------------------
\n
"
);
printf
(
" TOP
\n
--------------------
\n
"
);
for
(
int
*
spot
=
s
.
data
+
s
.
top
;
spot
>=
s
.
data
;
--
spot
)
{
for
(
int
*
spot
=
s
.
data
+
s
.
top
;
spot
>=
s
.
data
;
--
spot
)
{
printf
(
"%8d | %12d
\n
"
,
spot
-
s
.
data
,
*
spot
);
printf
(
"%8
l
d | %12d
\n
"
,
spot
-
s
.
data
,
*
spot
);
}
}
printf
(
"--------------------
\n
BOTTOM
\n
"
);
printf
(
"--------------------
\n
BOTTOM
\n
"
);
}
else
{
}
else
{
printf
(
"STACK EMPTY
\n
"
);
printf
(
"STACK EMPTY
\n
"
);
}
}
}
}
void
stack_clone
(
stack
s
,
stack
*
clone
)
{
void
stack_clone
(
stack
s
,
stack
*
clone
)
{
clone
->
top
=
s
.
top
;
clone
->
top
=
s
.
top
;
clone
->
capacity
=
s
.
capacity
;
clone
->
capacity
=
s
.
capacity
;
clone
->
data
=
malloc
(
sizeof
(
int
)
*
s
.
capacity
);
clone
->
data
=
malloc
(
sizeof
(
int
)
*
s
.
capacity
);
for
(
int
i
=
0
;
i
<=
s
.
top
&&
i
<
s
.
capacity
;
i
++
)
{
for
(
int
i
=
0
;
i
<=
s
.
top
&&
i
<
s
.
capacity
;
i
++
)
{
clone
->
data
[
i
]
=
s
.
data
[
i
];
clone
->
data
[
i
]
=
s
.
data
[
i
];
}
}
}
}
int
get_length
(
stack
s
)
int
get_length
(
stack
s
)
{
{
return
s
.
top
+
1
;
return
s
.
top
+
1
;
}
}
This diff is collapsed.
Click to expand it.
stack_test.c
+
3
−
2
View file @
18d33345
#include
"minunit.h"
#include
"minunit.h"
#include
"stack.h"
#include
"stack.h"
#include
<stdlib.h>
MU_TEST
(
stack_init_test
)
{
MU_TEST
(
stack_init_test
)
{
// Arrange
// Arrange
...
@@ -20,8 +21,8 @@ MU_TEST_SUITE(stack_test_suite) {
...
@@ -20,8 +21,8 @@ MU_TEST_SUITE(stack_test_suite) {
MU_RUN_TEST
(
stack_init_test
);
MU_RUN_TEST
(
stack_init_test
);
}
}
int
main
()
{
int
main
()
{
MU_RUN_SUITE
(
stack_test_suite
);
MU_RUN_SUITE
(
stack_test_suite
);
MU_REPORT
();
MU_REPORT
();
return
MU_EXIT_CODE
;
return
MU_EXIT_CODE
;
}
}
\ No newline at end of file
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