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
c445c829
Commit
c445c829
authored
9 years ago
by
Fernando Erd
Browse files
Options
Downloads
Patches
Plain Diff
QUICK SORT FUNCIONANDO PORRA
parent
7e192dec
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Arquivos/QuickSort.c
+51
-24
51 additions, 24 deletions
Arquivos/QuickSort.c
with
51 additions
and
24 deletions
Arquivos/QuickSort.c
+
51
−
24
View file @
c445c829
...
...
@@ -14,30 +14,56 @@ void printVetor( int Vetor[], int n ) {
printf
(
"%d "
,
Vetor
[
i
]
);
printf
(
"
\n
"
);
}
int
Mediana
(
int
Esquerda
,
int
Meio
,
int
Direita
)
{
if
((
Esquerda
>=
Direita
&&
Esquerda
<=
Meio
)
||
(
Esquerda
>=
Meio
&&
Esquerda
<=
Direita
))
return
Esquerda
;
if
((
Direita
>=
Esquerda
&&
Direita
<=
Meio
)
||
(
Direita
>=
Meio
&&
Direita
<=
Esquerda
))
return
Direita
;
else
return
Meio
;
int
Mediana
(
int
*
Vetor
,
int
esq
,
int
dir
)
{
int
aux
;
aux
=
(
dir
+
esq
)
/
2
;
// elem. do meio do vetor
//mediana dos 3 numeros
if
(
(
Vetor
[
esq
]
>=
Vetor
[
aux
])
&&
(
Vetor
[
esq
]
<=
Vetor
[
dir
])
)
return
esq
;
else
if
(
(
Vetor
[
esq
]
>=
Vetor
[
dir
])
&&
(
Vetor
[
esq
]
<=
Vetor
[
aux
])
)
return
esq
;
else
if
(
(
Vetor
[
dir
]
>=
Vetor
[
aux
])
&&
(
Vetor
[
dir
]
<=
Vetor
[
esq
])
)
return
dir
;
else
if
(
(
Vetor
[
dir
]
>=
Vetor
[
esq
])
&&
(
Vetor
[
dir
]
<=
Vetor
[
aux
])
)
return
dir
;
else
if
(
(
Vetor
[
aux
]
>=
Vetor
[
esq
])
&&
(
Vetor
[
aux
]
<=
Vetor
[
dir
])
)
return
aux
;
else
if
(
(
Vetor
[
aux
]
>=
Vetor
[
dir
])
&&
(
Vetor
[
aux
]
<=
Vetor
[
esq
])
)
return
aux
;
}
int
Particao
(
int
Vetor
[],
int
Esquerda
,
int
Direita
)
{
int
Pivo
,
i
,
j
;
int
Particao
(
int
*
Vetor
,
int
esq
,
int
dir
)
{
int
i
,
j
,
pivo
,
aux
;
aux
=
Mediana
(
Vetor
,
esq
,
dir
);
pivo
=
Vetor
[
aux
];
printf
(
"%d
\n
"
,
pivo
);
i
=
esq
;
j
=
dir
;
while
(
i
<
j
)
{
Pivo
=
Vetor
[
Direita
];
i
=
(
Esquerda
-
1
);
for
(
j
=
Esquerda
;
j
<=
Direita
-
1
;
j
++
)
{
if
(
Vetor
[
j
]
<=
Pivo
)
{
while
(
(
Vetor
[
i
]
<=
pivo
)
&&
(
i
<
dir
)
)
i
++
;
Troca
(
Vetor
,
i
,
j
);
}
while
(
Vetor
[
j
]
>
pivo
)
j
--
;
if
(
i
<
j
)
Troca
(
Vetor
,
j
,
i
);
}
Troca
(
Vetor
,
i
+
1
,
Direita
);
return
(
i
+
1
);
printVetor
(
Vetor
,
18
);
Vetor
[
esq
]
=
Vetor
[
j
];
Vetor
[
j
]
=
pivo
;
return
j
;
}
void
QuickSortRecursivo
(
int
Vetor
[],
int
Esquerda
,
int
Direita
)
{
...
...
@@ -79,8 +105,9 @@ void QuickSortIterativo (int Vetor[], int Esquerda, int Direita) {
}
int
main
()
{
int
Vetor
[]
=
{
5
1
,
2
,
45
,
95
,
43
,
78
,
1
2
,
32
};
int
Vetor
[]
=
{
1
,
2
,
3
,
4
,
5
,
8
,
6
,
4
,
43
,
43
,
56
,
23
,
43
,
4
,
3
,
75
,
34
2
,
5
32
};
int
n
=
sizeof
(
Vetor
)
/
sizeof
(
*
Vetor
);
QuickSortRecursivo
(
Vetor
,
0
,
n
-
1
);
printVetor
(
Vetor
,
n
);
QuickSortIterativo
(
Vetor
,
0
,
n
-
1
);
printVetor
(
Vetor
,
n
);
}
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