Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Alg 2
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
Vinícius Fontoura
Alg 2
Commits
1a9b797d
Commit
1a9b797d
authored
2 years ago
by
Vinícius Fontoura
Browse files
Options
Downloads
Patches
Plain Diff
number of comparisons fixed
parent
3acc4712
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
t1/ordenacao.c
+10
-10
10 additions, 10 deletions
t1/ordenacao.c
t1/ordenacao.o
+0
-0
0 additions, 0 deletions
t1/ordenacao.o
t1/trab
+0
-0
0 additions, 0 deletions
t1/trab
with
10 additions
and
10 deletions
t1/ordenacao.c
+
10
−
10
View file @
1a9b797d
...
...
@@ -49,14 +49,14 @@ int buscaBinariaCompleta(int vetor[], int tam, int inicio, int valor, int* numCo
meio
=
(
tam
+
inicio
)
/
2
;
//confere no meio
if
(
vetor
[
meio
]
==
valor
)
{
*
numComparacoes
+=
1
;
if
(
vetor
[
meio
]
==
valor
)
{
return
meio
;
}
//busca a esquerda
if
(
vetor
[
meio
]
>
valor
)
{
*
numComparacoes
+=
1
;
if
(
vetor
[
meio
]
>
valor
)
{
return
buscaBinariaCompleta
(
vetor
,
meio
-
1
,
inicio
,
valor
,
numComparacoes
);
}
//busca a direita
...
...
@@ -75,14 +75,14 @@ int buscaBinaria(int vetor[], int tam, int valor, int* numComparacoes){
}
//confere no meio
if
(
vetor
[
meio
]
==
valor
)
{
*
numComparacoes
+=
1
;
if
(
vetor
[
meio
]
==
valor
)
{
return
meio
;
}
// busca a esquerda
if
(
vetor
[
meio
]
>
valor
)
{
*
numComparacoes
+=
1
;
if
(
vetor
[
meio
]
>
valor
)
{
return
buscaBinariaCompleta
(
vetor
,
meio
-
1
,
a
,
valor
,
numComparacoes
);
}
//busca a direita
...
...
@@ -94,8 +94,8 @@ int busca(int vetor[], int a, int b, int valor, int* numComparacoes) {
int
meio
;
//caso base
if
(
a
>
b
)
{
if
(
valor
>
vetor
[
a
])
{
*
numComparacoes
+=
1
;
if
(
valor
>
vetor
[
a
])
{
return
a
+
1
;
}
return
a
;
...
...
@@ -103,14 +103,14 @@ int busca(int vetor[], int a, int b, int valor, int* numComparacoes) {
meio
=
(
a
+
b
)
/
2
;
//confere no meio
if
(
vetor
[
meio
]
==
valor
)
{
*
numComparacoes
+=
1
;
if
(
vetor
[
meio
]
==
valor
)
{
return
meio
+
1
;
}
// busca a esquerda
if
(
vetor
[
meio
]
>
valor
)
{
*
numComparacoes
+=
1
;
if
(
vetor
[
meio
]
>
valor
)
{
return
busca
(
vetor
,
a
,
meio
-
1
,
valor
,
numComparacoes
);
}
//busca a direita
...
...
@@ -178,8 +178,8 @@ int selectionSortCompleto(int vetor[], int a, int b, int* numComparacoes) {
//do inicio ate o fim do vetor, checamos qual eh o menor valor
for
(
int
i
=
a
;
i
<
b
;
i
++
)
{
//se o valor em i for < que o valor em inicio
if
(
vetor
[
i
]
<
vetor
[
inicio
])
{
*
numComparacoes
+=
1
;
if
(
vetor
[
i
]
<
vetor
[
inicio
])
{
//marca o elemento em i como o menor
menor
=
i
;
//ajusta o inicio para i
...
...
@@ -233,8 +233,8 @@ void merge(int v[], int a, int m, int b, int* numComparacoes) {
//se o vetor a direita tiver acabado OU
//o vetor a esquerda acabo E
//o elemento do primeiro for <= ao elemento do segundo
if
(
j
>
b
||
(
i
<=
m
&&
v
[
i
]
<=
v
[
j
]))
{
*
numComparacoes
+=
1
;
if
(
j
>
b
||
(
i
<=
m
&&
v
[
i
]
<=
v
[
j
]))
{
//marca o elemento em i
p
=
i
;
i
++
;
...
...
@@ -284,8 +284,8 @@ int particionar(int v[], int a, int b,int* numComparacoes) {
m
=
a
;
//percorre o vetor e faz a troca se o elemento em i é <= ao pivo
for
(
int
i
=
a
;
i
<
b
;
i
++
)
{
if
(
v
[
i
]
<=
x
)
{
*
numComparacoes
+=
1
;
if
(
v
[
i
]
<=
x
)
{
troca
(
v
,
m
,
i
);
m
++
;
}
...
...
This diff is collapsed.
Click to expand it.
t1/ordenacao.o
+
0
−
0
View file @
1a9b797d
No preview for this file type
This diff is collapsed.
Click to expand it.
t1/trab
+
0
−
0
View file @
1a9b797d
No preview for this file type
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