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;
}
Como agendar um backup automático do PostgreSQL no Cron evitando o problema de senha
Como preparar o Vim/Neovim para corrigir ortografia em português
Dark Web e Malwares na internet, quanto custa?
Configuração básica do Conky para mostrar informações sobre a sua máquina no Desktop
Como verificar o hash de um arquivo baixado da Internet e como criar um hash
Debian 12 - IPTABLES - removendo NFTABLES
OverWatch 2 - Abrindo portas do jogo no Iptables.
Como instalar o adaptador wifi USB Intelbras ACtion A1200 no Linux Mint
Como normalizar seus arquivos MP3 para que fiquem no mesmo volume
[C/C++] BRT - Bulk Renaming Tool
[Shell Script] Criação de Usuarios , Grupo e instalação do servidor de arquivos samba
[Shell Script] Tire screenshots com Scrot facilmente com Zscrot
[Shell Script] DioPSI - Script multidistro para instalar programas
[Shell Script] ARS Vídeos - Cortador de vídeos e webcam shooter