Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
controle-c-001
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-001
Commits
4d5db955
Commit
4d5db955
authored
3 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Ex 4
parent
12ab84a9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
ex4/Makefile
+2
-2
2 additions, 2 deletions
ex4/Makefile
ex4/main.c
+42
-18
42 additions, 18 deletions
ex4/main.c
ex4/stack.c
+58
-0
58 additions, 0 deletions
ex4/stack.c
ex4/stack.h
+30
-0
30 additions, 0 deletions
ex4/stack.h
with
132 additions
and
20 deletions
ex4/Makefile
+
2
−
2
View file @
4d5db955
...
...
@@ -13,8 +13,8 @@ default: $(TARGET)
run
:
$(TARGET)
./
$<
$(TARGET)
:
main.o
$(
CC
)
main.o
$(
CFLAGS
)
$(
LIBS
)
-o
$@
$(TARGET)
:
main.o
stack.o
$(
CC
)
main.o
stack.o
$(
CFLAGS
)
$(
LIBS
)
-o
$@
clean
:
-
rm
-f
*
.o
...
...
This diff is collapsed.
Click to expand it.
ex4/main.c
+
42
−
18
View file @
4d5db955
...
...
@@ -16,29 +16,53 @@
#include
<stdlib.h>
#include
<string.h>
#include
"stack.h"
int
main
()
{
// int32_t values_length = 5;
// double values[values_length];
int32_t
tab_length
=
7
;
double
tab
[
tab_length
];
for
(
int32_t
i
=
0
;
i
<
tab_length
;
i
+=
1
)
{
double
number
;
scanf
(
"%lf"
,
&
number
);
tab
[
i
]
=
number
;
}
int32_t
interv
[
tab_length
];
interv
[
0
]
=
1
;
stack
s
;
stack_init
(
&
s
,
1000
);
stack_push
(
&
s
,
0
);
for
(
int32_t
i
=
0
;
i
<
tab_length
;
i
+=
1
)
{
while
(
true
)
{
int32_t
top_value
;
stack_peek
(
s
,
&
top_value
);
if
(
stack_is_empty
(
s
)
||
tab
[
top_value
]
>
tab
[
i
])
{
break
;
}
stack_pop
(
&
s
,
&
top_value
);
}
// for (int32_t i = 0; i < values_length; i += 1) {
// double value;
// scanf("%lf", &value);
// values[i] = value;
// }
if
(
stack_is_empty
(
s
))
{
interv
[
i
]
=
i
+
1
;
}
else
{
int32_t
top_value
;
stack_peek
(
s
,
&
top_value
);
interv
[
i
]
=
i
-
top_value
;
}
// int32_t values_length = 5
;
// int32_t values[values_length];
stack_push
(
&
s
,
i
)
;
}
// for (int32_t i = 0; i < values_length; i += 1) {
// int32_t value;
// scanf("%d", &value);
// values[i] = value;
// }
printf
(
"
\n
"
);
// char a[100];
// int32_t b;
// scanf("%s %d", a, &b);
// printf("%s %d\n", a, b);
for
(
int32_t
i
=
0
;
i
<
tab_length
;
i
+=
1
)
{
printf
(
"%d
\n
"
,
interv
[
i
]);
}
stack_destroy
(
&
s
);
return
EXIT_SUCCESS
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ex4/stack.c
0 → 100644
+
58
−
0
View file @
4d5db955
/**
* @file stack.c
* @author Florian Burgener (florian.burgener@etu.hesge.ch)
* @brief Implémentation de la librairie stack.
* @version 1.0
* @date 2021-12-07
*
* @copyright Copyright (c) 2021
*
*/
#include
"stack.h"
#include
<stdbool.h>
#include
<stdlib.h>
void
stack_init
(
stack
*
s
,
int
size
)
{
s
->
size
=
size
;
s
->
top
=
-
1
;
s
->
data
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
s
->
size
);
}
bool
stack_is_empty
(
stack
s
)
{
return
s
.
top
==
-
1
;
}
void
stack_push
(
stack
*
s
,
int
val
)
{
if
(
s
->
size
==
s
->
top
+
1
)
{
return
;
}
s
->
top
+=
1
;
s
->
data
[
s
->
top
]
=
val
;
}
void
stack_pop
(
stack
*
s
,
int
*
val
)
{
if
(
stack_is_empty
(
*
s
))
{
return
;
}
stack_peek
(
*
s
,
val
);
s
->
top
-=
1
;
}
void
stack_peek
(
stack
s
,
int
*
val
)
{
if
(
stack_is_empty
(
s
))
{
return
;
}
*
val
=
s
.
data
[
s
.
top
];
}
void
stack_destroy
(
stack
*
s
)
{
s
->
size
=
-
1
;
s
->
top
=
-
1
;
free
(
s
->
data
);
s
->
data
=
NULL
;
}
This diff is collapsed.
Click to expand it.
ex4/stack.h
0 → 100644
+
30
−
0
View file @
4d5db955
/**
* @file stack.h
* @author Florian Burgener (florian.burgener@etu.hesge.ch)
* @brief Header de librairie stack.
* @version 1.0
* @date 2021-12-07
*
* @copyright Copyright (c) 2021
*
*/
#ifndef STACK_H
#define STACK_H
#include
<stdbool.h>
typedef
struct
_stack
{
int
size
;
int
top
;
int
*
data
;
}
stack
;
void
stack_init
(
stack
*
s
,
int
size
);
bool
stack_is_empty
(
stack
s
);
void
stack_push
(
stack
*
s
,
int
val
);
void
stack_pop
(
stack
*
s
,
int
*
val
);
void
stack_peek
(
stack
s
,
int
*
val
);
void
stack_destroy
(
stack
*
s
);
#endif
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