Commit ceb4fa69 authored by Samuel Oliveira's avatar Samuel Oliveira

Classe pilha adicionada a aula 5

parent 59822f89
{
"files.associations": {
"iostream": "cpp"
}
}
\ No newline at end of file
#include <iostream>
using namespace std;
template <class T>
class Pilha{
private:
int size;
int top;
T* elements;
public:
Pilha(int s){
this->size = s;
this->top = -1;
this->elements = new T[size];
}
void push(T element){
if(top == (size -1)){
cout << "Pilha cheia" << endl;
}else{
this->elements[++top] = element;
}
}
void pop(){
if(top == -1){
cout << "Pilha vazia" << endl;
}else{
this->elements[top--];
}
}
bool isEmpty(){
if(top == -1){
return true;
}else{
return false;
}
}
T back(){
return this->elements[top];
}
};
\ No newline at end of file
#include <iostream>
#include "Pilha.hpp"
using namespace std;
int main(){
Pilha<int> pilha(3);
pilha.push(1);
pilha.push(2);
pilha.push(3);
pilha.push(4);
cout << pilha.back() << endl;
return 0;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment