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;
}
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Descritores de Arquivos e Swappiness
Como instalar no Linux Jogos da Steam só para Windows
Instalando o Team Viewer no Debian Trixie - problema no Policykit
O Que Fazer Após Instalar Ubuntu 25.04
Duvida na instalação do Kali (1)
Problema ao iniciar o Opensuse Tumbleweed (3)