Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Aula_Tads
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
Harbor 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
emsouza
Aula_Tads
Commits
bb65fe9b
Commit
bb65fe9b
authored
8 months ago
by
Eduardo Souza
Browse files
Options
Downloads
Patches
Plain Diff
[ADD] EstaCheia e EstaVazia
parent
3d40db6d
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
a.out
+0
-0
0 additions, 0 deletions
a.out
fila_edu_cir.c
+11
-0
11 additions, 0 deletions
fila_edu_cir.c
fila_edu_vetor_ot.c
+31
-19
31 additions, 19 deletions
fila_edu_vetor_ot.c
fila_edu_vetor_simples.c
+10
-0
10 additions, 0 deletions
fila_edu_vetor_simples.c
with
52 additions
and
19 deletions
a.out
+
0
−
0
View file @
bb65fe9b
No preview for this file type
This diff is collapsed.
Click to expand it.
fila_edu_cir.c
+
11
−
0
View file @
bb65fe9b
...
@@ -54,6 +54,17 @@ void destroi(struct Fila *fila) {
...
@@ -54,6 +54,17 @@ void destroi(struct Fila *fila) {
free
(
fila
);
free
(
fila
);
}
}
// Função para verificar se a fila está vazia
int
estaVazia
(
struct
Fila
*
f
)
{
return
f
->
tamanho
==
0
;
}
// Função para verificar se a fila está cheia
int
estaCheia
(
struct
Fila
*
f
)
{
return
f
->
tamanho
==
f
->
capacidade
;
}
int
main
()
{
int
main
()
{
/* PRIMEIRA FILA TEMPO */
/* PRIMEIRA FILA TEMPO */
struct
Fila
*
fila1
=
cria
(
500
);
struct
Fila
*
fila1
=
cria
(
500
);
...
...
This diff is collapsed.
Click to expand it.
fila_edu_vetor_ot.c
+
31
−
19
View file @
bb65fe9b
...
@@ -41,6 +41,7 @@ int insere(struct Fila *fila, float dado) {
...
@@ -41,6 +41,7 @@ int insere(struct Fila *fila, float dado) {
return
-
1
;
return
-
1
;
}
}
}
}
printf
(
"Inserindo %.2f na posição %d
\n
"
,
dado
,
fila
->
fim
+
1
);
fila
->
fim
++
;
fila
->
fim
++
;
fila
->
dados
[
fila
->
fim
]
=
dado
;
fila
->
dados
[
fila
->
fim
]
=
dado
;
fila
->
tamanho
++
;
fila
->
tamanho
++
;
...
@@ -72,28 +73,39 @@ void destroi(struct Fila *fila) {
...
@@ -72,28 +73,39 @@ void destroi(struct Fila *fila) {
free
(
fila
);
free
(
fila
);
}
}
int
main
()
{
// Função para verificar se a fila está vazia
int
estaVazia
(
struct
Fila
*
f
)
{
/* PRIMEIRA FILA TEMPO */
return
f
->
tamanho
==
0
;
struct
Fila
*
fila1
=
cria
(
500
);
struct
timespec
inicio
,
fim
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
inicio
);
// Teste com várias inserções e remoções
// Vamos fazer 1000000 operações de enfileiramento e desenfileiramento para medir a performance
for
(
int
i
=
0
;
i
<
1000000
;
i
++
)
{
if
(
fila1
->
tamanho
<
fila1
->
capacidade
)
{
// Insere metade das vezes
insere
(
fila1
,
(
float
)
i
);
}
if
(
i
%
2
==
0
&&
fila1
->
tamanho
>
0
)
{
// Remove metade das vezes
remove_fila
(
fila1
);
}
}
// Função para verificar se a fila está cheia
int
estaCheia
(
struct
Fila
*
f
)
{
return
f
->
tamanho
==
f
->
capacidade
;
}
}
clock_gettime
(
CLOCK_MONOTONIC
,
&
fim
);
double
tempo_gasto
=
(
fim
.
tv_sec
-
inicio
.
tv_sec
)
+
(
fim
.
tv_nsec
-
inicio
.
tv_nsec
)
/
1000000000
.
0
;
printf
(
"Tempo gasto: %.2f segundos
\n
"
,
tempo_gasto
);
destroi
(
fila1
);
int
main
()
{
// /* PRIMEIRA FILA TEMPO */
// struct Fila *fila1 = cria(500);
// struct timespec inicio, fim;
// clock_gettime(CLOCK_MONOTONIC, &inicio);
// // Teste com várias inserções e remoções
// // Vamos fazer 1000000 operações de enfileiramento e desenfileiramento para medir a performance
// for (int i = 0; i < 1000000; i++) {
// if (fila1->tamanho < fila1->capacidade) { // Insere metade das vezes
// insere(fila1, (float) i);
// }
// if (i % 2 == 0 && fila1->tamanho > 0) { // Remove metade das vezes
// remove_fila(fila1);
// }
// }
// clock_gettime(CLOCK_MONOTONIC, &fim);
// double tempo_gasto = (fim.tv_sec - inicio.tv_sec) + (fim.tv_nsec - inicio.tv_nsec) / 1000000000.0;
// printf("Tempo gasto: %.2f segundos\n", tempo_gasto);
// destroi(fila1);
/*SEGUNDA FILA TEMPO*/
/*SEGUNDA FILA TEMPO*/
...
...
This diff is collapsed.
Click to expand it.
fila_edu_vetor_simples.c
+
10
−
0
View file @
bb65fe9b
...
@@ -57,6 +57,16 @@ void destroi(struct Fila *fila) {
...
@@ -57,6 +57,16 @@ void destroi(struct Fila *fila) {
free
(
fila
);
free
(
fila
);
}
}
// Função para verificar se a fila está vazia
int
estaVazia
(
struct
Fila
*
f
)
{
return
f
->
tamanho
==
0
;
}
// Função para verificar se a fila está cheia
int
estaCheia
(
struct
Fila
*
f
)
{
return
f
->
tamanho
==
f
->
capacidade
;
}
int
main
()
{
int
main
()
{
/* PRIMEIRA FILA TEMPO */
/* PRIMEIRA FILA TEMPO */
...
...
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