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
00a64462
Commit
00a64462
authored
May 11, 2022
by
Alan de Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Conclusão do exercício 7
parent
870cf896
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
239 additions
and
10 deletions
+239
-10
exercicio1.cpp
exercicio1.cpp
+0
-10
exercicio6.cpp
exercicio6.cpp
+89
-0
exercicio7.cpp
exercicio7.cpp
+150
-0
No files found.
exercicio1.cpp
View file @
00a64462
...
...
@@ -104,21 +104,12 @@ int main(int argc, char* argv[]) {
meuDeque
.
insereInicio
(
7
);
auto
d
=
meuDeque
.
removeFim
();
/*printf ("primeiro %d ", d);
d = meuDeque.removeFim();
printf ("segundo %d ", d);
d = meuDeque.removeFim();
printf ("terceiro %d ", d);
d = meuDeque.removeinicio();
printf ("quarto %d ", d);
d = meuDeque.removeinicio();*/
while
(
d
!=
-
1
)
{
printf
(
"%d "
,
d
);
d
=
meuDeque
.
removeinicio
();
}
return
0
;
}
\ No newline at end of file
exercicio6.cpp
0 → 100644
View file @
00a64462
#include <iostream>
template
<
class
T
>
class
PilhaMin
{
public
:
void
empilha
(
T
elemento
)
{
N
++
;
elementos
[
N
-
1
]
=
elemento
;
}
T
desempilha
()
{
if
(
N
>
0
)
{
N
--
;
return
elementos
[
N
];
}
else
return
-
1
;
}
T
topo
()
{
if
(
N
>
0
)
return
elementos
[
N
-
1
];
else
return
-
1
;
}
T
obterMinimo
()
{
T
*
minimo
=
&
elementos
[
0
];
for
(
int
i
=
1
;
i
<
N
;
i
++
)
{
if
(
elementos
[
i
]
<
*
(
minimo
))
minimo
=
&
elementos
[
i
];
}
return
*
(
minimo
);
}
private
:
static
const
int
MAX
=
900
;
int
N
=
0
;
T
elementos
[
MAX
];
};
void
preencherPilha
(
PilhaMin
<
char
>
&
pilha
)
{
pilha
.
empilha
(
'b'
);
pilha
.
empilha
(
'c'
);
pilha
.
empilha
(
'd'
);
pilha
.
empilha
(
'e'
);
pilha
.
empilha
(
'f'
);
pilha
.
empilha
(
'g'
);
pilha
.
empilha
(
'h'
);
pilha
.
empilha
(
'i'
);
pilha
.
empilha
(
'j'
);
pilha
.
empilha
(
'k'
);
pilha
.
empilha
(
'l'
);
pilha
.
empilha
(
'm'
);
pilha
.
empilha
(
'a'
);
pilha
.
empilha
(
'1'
);
pilha
.
empilha
(
'n'
);
pilha
.
empilha
(
'o'
);
pilha
.
empilha
(
'p'
);
pilha
.
empilha
(
'q'
);
pilha
.
empilha
(
'r'
);
pilha
.
empilha
(
's'
);
pilha
.
empilha
(
't'
);
pilha
.
empilha
(
'u'
);
pilha
.
empilha
(
'v'
);
pilha
.
empilha
(
'w'
);
pilha
.
empilha
(
'x'
);
pilha
.
empilha
(
'y'
);
pilha
.
empilha
(
'z'
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
PilhaMin
<
char
>
pilha
;
preencherPilha
(
pilha
);
std
::
cout
<<
"Mínimo: "
<<
pilha
.
obterMinimo
()
<<
std
::
endl
;
return
0
;
}
\ No newline at end of file
exercicio7.cpp
0 → 100644
View file @
00a64462
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
using
namespace
std
;
template
<
class
D
>
class
container
{
public
:
container
*
proximo
;
D
elemento
;
};
template
<
class
T
,
class
Container
=
container
<
T
>>
class
Fila
{
public
:
void
enfilera
(
T
elem
)
{
auto
cont
=
new
container
<
T
>
();
cont
->
elemento
=
elem
;
if
(
fim
!=
nullptr
)
fim
->
proximo
=
cont
;
else
inicio
=
cont
;
fim
=
cont
;
}
T
desenfilera
()
{
if
(
inicio
!=
nullptr
)
{
T
elemento
=
inicio
->
elemento
;
Container
*
i
=
inicio
;
inicio
=
inicio
->
proximo
;
if
(
inicio
==
nullptr
)
fim
=
nullptr
;
delete
i
;
return
elemento
;
}
else
return
-
1
;
}
T
frente
()
{
if
(
inicio
!=
nullptr
)
return
inicio
->
elemento
;
else
return
-
1
;
}
private
:
Container
*
inicio
=
nullptr
;
Container
*
fim
=
nullptr
;
};
template
<
class
T
>
class
Pilha
{
public
:
void
empilha
(
T
elemento
)
{
N
++
;
elementos
[
N
-
1
]
=
elemento
;
}
T
desempilha
()
{
if
(
N
>
0
)
{
N
--
;
return
elementos
[
N
];
}
else
return
-
1
;
}
T
topo
()
{
if
(
N
>
0
)
return
elementos
[
N
-
1
];
else
return
-
1
;
}
private
:
static
const
int
MAX
=
900
;
int
N
=
0
;
T
elementos
[
MAX
];
};
bool
operador
(
char
s
)
{
vector
<
char
>
operadores
=
{
'*'
,
'+'
,
'-'
,
'/'
};
for
(
char
o
:
operadores
)
{
if
(
o
==
s
)
return
true
;
}
return
false
;
}
bool
parenteses
(
char
s
)
{
vector
<
char
>
operadores
=
{
'('
,
')'
};
for
(
char
o
:
operadores
)
{
if
(
o
==
s
)
return
true
;
}
return
false
;
}
string
polonisar
(
string
expr
)
{
auto
stream
=
stringstream
{
expr
};
char
aux
;
Pilha
<
char
>
operadores
;
Fila
<
char
>
fila_retorno
;
while
(
stream
>>
aux
)
{
if
(
aux
!=
'('
)
if
(
operador
(
aux
))
operadores
.
empilha
(
aux
);
else
if
(
aux
==
')'
)
{
while
(
operadores
.
topo
()
!=
-
1
){
fila_retorno
.
enfilera
(
operadores
.
desempilha
());
}
}
else
fila_retorno
.
enfilera
(
aux
);
}
string
exp_retorno
;
while
(
fila_retorno
.
frente
()
!=
-
1
)
{
exp_retorno
+=
fila_retorno
.
desenfilera
();
}
return
exp_retorno
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
string
expr
=
"((A+B)*(C-(F/D)))"
;
cout
<<
"Expressão: "
<<
expr
<<
endl
;
cout
<<
"Expressão Polonesa Reversa: "
<<
polonisar
(
expr
)
<<
endl
;
return
0
;
}
\ No newline at end of file
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