Enviado em 10/11/2018 - 22:50h
Boa noite pessoal.#ifndef CELL_H
#define CELL_H
class Cell
{
public:
Cell(int value, Cell *next);
~Cell();
int value() const { return m_value; }
Cell *next() const {return m_next; }
private:
int m_value;
Cell *m_next;
};
#endif
#include "cell.h"
#include <iostream>
using namespace std;
Cell::Cell(int value, Cell *next): m_value(value), m_next(next)
{
//Empty
}
#include "cell.h"
#include <iostream>
using namespace std;
Cell::Cell(int value, Cell *next): m_value(value), m_next(next)
{
//Empty
}
#include "stack.h"
#include "cell.h"
#include <assert.h>
#include <iostream>
using namespace std;
Stack::Stack():m_firstCellPtr(nullPtr), m_size(0)
{
//Empty
}
void Stack::push(int value)
{
m_firstCellPtr = new Cell(value, m_firstCellPtr);
++m_size;
}
int Stack::top()
{
assert(!empty());
return m_firstCellPtr->getValue();
}
void Stack::pop()
{
assert(!empty());
Cell *deleteCellPtr = m_firstCellPtr;
m_firstCellPtr = m_firstCellPtr->getNext();
delete deleteCellPtr;
--m_size;
}
int Stack::size() const
{
return m_size;
}
bool Stack::empty() const
{
return (m_firstCellPtr == nullPtr);
}
#include <string.h>
#include <iostream>
#include "cell.h"
#include "stack.h"
using namespace std;
int main(int argc, char const *argv[])
{
Stack s;
s.push(1);
s.push(2);
s.push(3);
cout <<"\nTop: " << s.top() <<", size: " << s.size() <<", empty " << (s.empty() ? "true" : "false") << endl;
s.pop();
s.pop();
s.push(4);
cout <<"\nTop: " << s.top() <<", size: " << s.size() <<", empty " << (s.empty() ? "true" : "false") << endl;
return 0;
}
Aprenda a Gerenciar Permissões de Arquivos no Linux
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Dando - teoricamente - um gás no Gnome-Shell do Arch Linux
Como instalar o Google Cloud CLI no Ubuntu/Debian
Mantenha seu Sistema Leve e Rápido com a Limpeza do APT!
Procurando vídeos de YouTube pelo terminal e assistindo via mpv (2025)
Alguém que utilize o Warsaw do BB no Ubuntu 24.04 (4)
estou com problemas aqui no manjaro. (3)
warsaw parou de funcionar após atualização do sistema (solução) (7)