-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPila.cpp
48 lines (43 loc) · 934 Bytes
/
Pila.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <iostream>
using namespace std;
struct Pila{
char dato;
Pila *sig;
};
void agregarPila(Pila *&,char);
void sacarPila(Pila *&,char &);
int main() {
Pila *cima=NULL;
char dato;
char rpt;
do{
printf("Caracter:");
cin>>dato;
agregarPila(cima,dato);
printf("Otro caracter? s/n\n");
cin>>rpt;
}
while((rpt=='s') || (rpt=='S'));
{
printf("\n");
while (cima!=NULL){
sacarPila(cima,dato);
cout<<dato;
}
}
return 0;
}
void agregarPila(Pila *&cima,char n){
Pila *nueva_pila= new Pila();
nueva_pila->dato=n;
nueva_pila->sig=cima;
cima=nueva_pila;
printf("Caracter agregado\n");
};
void sacarPila(Pila *&cima, char &n){
Pila *aux= cima;
n= aux->dato;
cima= aux->sig;
delete aux;
};