Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
QuickSort e MergeSort - Algoritmos 2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leonardo Krambeck
QuickSort e MergeSort - Algoritmos 2
Commits
81e92bc1
Commit
81e92bc1
authored
Oct 16, 2019
by
Leonardo Krambeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implementa insertion e faz com que analise.c teste para tamanhos crescentes
parent
3204fe04
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
24 deletions
+49
-24
analise.c
analise.c
+27
-18
lib_ordena.c
lib_ordena.c
+22
-6
No files found.
analise.c
View file @
81e92bc1
...
...
@@ -4,8 +4,7 @@
#include "lib_ordena.h"
#define MAX_IT 5
#define TAM_VETOR 50
#define LIMITE 1000000
double
timestamp
(
void
)
{
...
...
@@ -18,28 +17,38 @@ int main () {
int
i
,
tam
;
double
ini
,
fim
,
soma_tempo
;
tam
=
TAM_VETOR
;
int
v
[
tam
];
/* Mude aqui o numero de iterações e nome do algoritmo */
int
MAX_IT
=
100
;
char
*
algoritmo
=
"mergesort_basico (R)"
;
gera_vetor_randomico
(
v
,
tam
);
soma_tempo
=
0
;
for
(
i
=
0
;
i
<
MAX_IT
;
i
++
)
for
(
tam
=
10
;
tam
<=
LIMITE
;
tam
*=
10
)
{
printf
(
"
\n
"
)
;
imprime_vetor
(
v
,
tam
);
int
*
v
;
v
=
(
int
*
)
malloc
(
tam
*
sizeof
(
int
));
ini
=
timestamp
();
mergesort_melhorado
(
v
,
0
,
tam
-
1
);
fim
=
timestamp
();
/* Mude aqui o tipo de entrada */
gera_vetor_randomico
(
v
,
tam
);
soma_tempo
+=
(
fim
-
ini
);
soma_tempo
=
0
;
for
(
i
=
0
;
i
<
MAX_IT
;
i
++
)
{
/*imprime_vetor (v, tam);*/
imprime_vetor
(
v
,
tam
);
embaralha_vetor
(
v
,
tam
);
}
ini
=
timestamp
();
/* Mude aqui o algoritmo usado */
mergesort_basico
(
v
,
0
,
tam
-
1
);
fim
=
timestamp
();
soma_tempo
+=
(
fim
-
ini
);
printf
(
"
\n
Tempo medio do quicksort: %f segundos.
\n
"
,
soma_tempo
/
MAX_IT
);
/*imprime_vetor (v, tam);*/
embaralha_vetor
(
v
,
tam
);
}
printf
(
"Algoritmo: %25s | Iterações: %5d | Tamanho: %10d | Tempo: %15f milisegundos.
\n
"
,
algoritmo
,
MAX_IT
,
tam
,
soma_tempo
/
MAX_IT
);
free
(
v
);
}
return
0
;
}
lib_ordena.c
View file @
81e92bc1
...
...
@@ -47,8 +47,24 @@ void embaralha_vetor (int v[], int tam) {
}
}
void
inserctionsort
(
int
v
[],
int
ini
,
int
fim
)
{
printf
(
"implementar insertionsort
\n
"
);
void
insertionsort
(
int
v
[],
int
ini
,
int
fim
)
{
int
i
,
j
,
chave
;
int
tam
=
fim
-
ini
+
1
;
for
(
i
=
1
;
i
<
tam
;
i
++
)
{
chave
=
v
[
i
];
j
=
i
-
1
;
while
(
j
>=
0
&&
chave
<
v
[
j
]
)
{
v
[
j
+
1
]
=
v
[
j
];
j
--
;
}
v
[
j
+
1
]
=
chave
;
}
}
/* particiona com pivo no inicio */
...
...
@@ -293,8 +309,8 @@ int esta_ordenado (int v[], int meio)
/* testa se duas particoes do merge estão ordenadas invertidas */
int
esta_invertido
(
int
v
[],
int
ini
,
int
fim
)
{
/*
if ( v[ini] > v[fim] )
return 1;
falta inverter */
if
(
v
[
ini
]
>
v
[
fim
]
)
return
1
;
return
0
;
}
...
...
@@ -310,9 +326,9 @@ void mergesort_melhorado (int v[], int ini, int fim)
if
(
esta_ordenado
(
v
,
meio
))
printf
(
"ta ordenado lek
\n
"
);
else
if
(
esta_invertido
(
v
,
ini
,
fim
))
/*
else if (esta_invertido(v, ini, fim))
printf ("ta ordenado invertido lek\n");
/*
falta inverter */
falta inverter */
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment