0
Good evening! is my first post here so please in case I reported something wrong, feel free to fix it. I made a dynamic char list, but I’m having difficulty printing the entire list on the screen, when trying to print, it prints only the first character and then stops compiling stating that some of the other characters point to Nullptr. Below I will put the . h of the Node class ,my function and the main.
The Nodo class:
#include <iostream>
using namespace std;
class Nodo
{
protected:
char caractere;
Nodo* proximo;
Nodo* anterior;
public:
Nodo();
~Nodo();
void setcaractere(char c);
void setProximo(Nodo* p);
Nodo* getAnterior();
char getcaractere();
Nodo* getProximo();
void setAnterior(Nodo* anter);
};
Print function:
{
Nodo* ptr8 = new Nodo;
Nodo* ptr9 = new Nodo;
ptr9 = inicio;
for (int i = 0; i < tamanho; i++)
{
cout << ptr9->getcaractere() << endl;
ptr8 = inicio->getProximo();
ptr9 = ptr8;
}
}
My main:
#include "Nodo.h"
#include"Lista.h"
#include <iostream>
using namespace std;
int main()
{
Lista lista;
lista.push_front('a');
lista.push_back('b');
lista.push_back('c');
lista.push_front('d');
lista.imprimir();
lista.pop_back();
lista.pop_front();
if (!lista.empty())
{
cout << lista.front() << endl;
cout << lista.back() << endl;
}
else {
cout << "pilha vazia" << endl;
}
lista.remove();
lista.salvarTXT();
lista.back();
}
Thanks! Yes, I had created the pop, top and push function, but I didn’t put it because they were huge
– ProgramadoraMaluca
I understand. But without the compileable code, it’s hard to help. And these functions being immense is something to think about, because in general it has few lines, about 10/15.
– arfneto