Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Alg2TB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Fernando Erd
Alg2TB2
Commits
820c6fe8
Commit
820c6fe8
authored
9 years ago
by
Fernando Erd
Browse files
Options
Downloads
Patches
Plain Diff
Arrumando Pesquisa Sequencial
parent
e32ac312
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
Arquivos/Estruturas.h
+1
-1
1 addition, 1 deletion
Arquivos/Estruturas.h
Arquivos/Loteria
+0
-0
0 additions, 0 deletions
Arquivos/Loteria
Arquivos/Main.c
+31
-10
31 additions, 10 deletions
Arquivos/Main.c
Arquivos/Pesquisa.c
+2
-1
2 additions, 1 deletion
Arquivos/Pesquisa.c
with
34 additions
and
12 deletions
Arquivos/Estruturas.h
+
1
−
1
View file @
820c6fe8
...
...
@@ -4,5 +4,5 @@
#include
<stdlib.h>
#include
<stdbool.h>
#include
<sys/time.h>
#define TAM 1
5
//tamanho do vetor
#define TAM 1
00
//tamanho do vetor
#define NUMMAX 50 //constante que tem o máximo de valores
This diff is collapsed.
Click to expand it.
Arquivos/Loteria
+
0
−
0
View file @
820c6fe8
No preview for this file type
This diff is collapsed.
Click to expand it.
Arquivos/Main.c
+
31
−
10
View file @
820c6fe8
#include
"Estruturas.h"
#include
"Funções.h"
void
TempoSelectSort
(
int
*
Vetor
)
{
struct
timeval
inicio
,
final
;
int
tmili
,
i
;
gettimeofday
(
&
inicio
,
NULL
);
for
(
i
=
0
;
i
<
10000
;
i
++
)
{
GeraVetor
(
Vetor
);
SelectSort
(
Vetor
);
}
gettimeofday
(
&
final
,
NULL
);
tmili
=
(
int
)
(
1000
*
(
final
.
tv_sec
-
inicio
.
tv_sec
)
+
(
final
.
tv_usec
-
inicio
.
tv_usec
)
/
1000
);
printf
(
"O SelectSort Demorou %d Centesimos
\n
"
,
tmili
);
}
void
TempoBubbleSort
(
int
*
Vetor
)
{
struct
timeval
inicio
,
final
;
int
tmili
,
i
;
gettimeofday
(
&
inicio
,
NULL
);
for
(
i
=
0
;
i
<
10000
;
i
++
)
{
GeraVetor
(
Vetor
);
BubbleSort
(
Vetor
);
}
gettimeofday
(
&
final
,
NULL
);
tmili
=
(
int
)
(
1000
*
(
final
.
tv_sec
-
inicio
.
tv_sec
)
+
(
final
.
tv_usec
-
inicio
.
tv_usec
)
/
1000
);
printf
(
"O BubbleSort Demorou %d Centesimos
\n
"
,
tmili
);
}
int
main
()
{
int
Vetor
[
TAM
],
Escolhidos
[
4
];
struct
timeval
inicio
,
final
;
int
tmili
,
i
,
comando
;
int
comando
;
printf
(
"1 Para Jogar e 2 Para Comparar Algoritmos
\n
"
);
scanf
(
"%d"
,
&
comando
);
...
...
@@ -17,13 +44,7 @@ int main () {
ImprimeVetor
(
Vetor
);
break
;
case
2
:
gettimeofday
(
&
inicio
,
NULL
);
for
(
i
=
0
;
i
<
10000
;
i
++
)
{
GeraVetor
(
Vetor
);
SelectSort
(
Vetor
);
}
gettimeofday
(
&
final
,
NULL
);
tmili
=
(
int
)
(
1000
*
(
final
.
tv_sec
-
inicio
.
tv_sec
)
+
(
final
.
tv_usec
-
inicio
.
tv_usec
)
/
1000
);
printf
(
"O SelectSort Demorou %d Centesimos
\n
"
,
tmili
);
TempoSelectSort
(
Vetor
);
TempoBubbleSort
(
Vetor
);
}
}
This diff is collapsed.
Click to expand it.
Arquivos/Pesquisa.c
+
2
−
1
View file @
820c6fe8
...
...
@@ -23,10 +23,11 @@ int PesquisaBinaria (int *Vetor, int Elem) {
int
PesquisaSequencial
(
int
*
Vetor
,
int
Elem
)
{
int
i
;
Vetor
[
0
]
=
Elem
;
for
(
i
=
TAM
-
1
;
i
>=
0
;
i
++
)
{
for
(
i
=
0
;
i
<
TAM
;
i
++
)
{
if
(
Vetor
[
i
]
==
Elem
)
return
i
;
}
return
-
1
;
//-1 pq o elemento pode estar na posição zero
}
...
...
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