Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uff-Atividades-pilha-fila
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alan de Oliveira
uff-Atividades-pilha-fila
Commits
5769c424
Commit
5769c424
authored
Jun 12, 2022
by
Alan de Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comentando exercicio 3
parent
91127488
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
exercicio3.cpp
exercicio3.cpp
+20
-2
No files found.
exercicio3.cpp
View file @
5769c424
...
@@ -34,14 +34,33 @@ class Pilha {
...
@@ -34,14 +34,33 @@ class Pilha {
};
};
/**
* @brief Reescreva uma fila utilizando duas pilhas
* Descrição Abaixo
*
* @tparam T
*/
template
<
class
T
>
template
<
class
T
>
class
Fila
{
class
Fila
{
public
:
public
:
/**
* @brief Para enfileirar, apenas utilizamos a função de empilhar
*
* @param elem
*/
void
enfilera
(
T
elem
)
{
void
enfilera
(
T
elem
)
{
pilha
->
empilha
(
elem
);
pilha
->
empilha
(
elem
);
}
}
/**
* @brief Para desenfilerar,
* passo os elementos de uma pilha para outra, exeto o ultimo elemento
* guardo esse ultimo elemento para o retorno.
* Volto todos os elementos da pilha auxiliar para a pilha principal.
* @return T
*/
T
desenfilera
()
{
T
desenfilera
()
{
if
(
pilha
->
topo
()
==
-
1
)
if
(
pilha
->
topo
()
==
-
1
)
...
@@ -49,12 +68,11 @@ class Fila {
...
@@ -49,12 +68,11 @@ class Fila {
auto
paux
=
new
Pilha
<
T
>
();
auto
paux
=
new
Pilha
<
T
>
();
T
elemento
;
T
elemento
;
while
(
pilha
->
topo
()
!=
-
1
)
{
while
(
pilha
->
topo
()
!=
-
1
)
{
cout
<<
" "
<<
pilha
->
topo
();
elemento
=
pilha
->
desempilha
();
elemento
=
pilha
->
desempilha
();
if
(
pilha
->
topo
()
!=
-
1
)
if
(
pilha
->
topo
()
!=
-
1
)
paux
->
empilha
(
elemento
);
paux
->
empilha
(
elemento
);
}
}
cout
<<
endl
;
while
(
paux
->
topo
()
!=
-
1
)
{
while
(
paux
->
topo
()
!=
-
1
)
{
pilha
->
empilha
(
paux
->
desempilha
());
pilha
->
empilha
(
paux
->
desempilha
());
}
}
...
...
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