-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpila.h
40 lines (37 loc) · 784 Bytes
/
pila.h
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
#pragma once
#ifndef PILA_H
#define PILA_H
#include "listaenlazada.h"
template <class T>
class Pila
{
private:
ListaEnlazada<T> *almacenamiento;
int cantidad;
public:
Pila(){ //=O(n) - 2
this->cantidad = 0;
this->almacenamiento = new ListaEnlazada<T>();
}
void Push(T item){// O(1) - 7
almacenamiento->Agregar(item);
cantidad++;
}
void Pop(){ //O(1) - 7
if(cantidad > 0){
almacenamiento->EliminarInicial();
cantidad--;
}
}
T Peek(){ // O(1) - 3
if(cantidad > 0){
return almacenamiento->ObtenerInicial();
}else{
return nullptr;
}
}
int ObtenerCantidad(){ //O(1) - 1
return cantidad;
}
};
#endif // PILA_H