The exercise in question is this:
I already have this code in the header:
#ifndef HEADER_H
#define HEADER_H7
//Tipo dato Nodo
struct Nodo
{
int dato;
Nodo* izq;
Nodo* der;
};
//Tipo dato Estructura
struct Estructura
{
Nodo* inicio;
Nodo* fin;
};
void inicializarEstructura(Estructura& est);
//{PRE: 'est.inicio' es nullptr y ‘est.fin’ es nullptr}
#endif // HEADER_H
And this is the code that I have at the moment of the main:
//Tema 1. Ejercicios punteros.
#include <iostream>
#include <header.h>
using namespace std;
int main()
{
return 0;
}
void inicializarEstructura(Estructura& est)
{
//1º Aquí asigno memoria dinámica para cada nodo
Nodo* p = new Nodo;
Nodo* q = new Nodo;
Nodo* h = new Nodo;
//2º Asigno los punteros correspondientes
//2.1º Primero los punteros de la Estructura "est" a nodo
*est.inicio = *q->der;
*est.fin = *h->izq;
//2.2º Segundo los punteros de nodo a nodo
*q->der = *est.fin;
*p->izq = *est.inicio;
est.fin->izq = p->dato;
}
I miss this error:
I only get the error when I try to point with the left variable (node type) of the third node, to the data variable (int type) of the 1st node.
How do I solve it?
Thanks in advance.
PS: Receiving an answer is important to me, I need to understand the concept of pointer correctly, and I think that by seeing this exercise solved I will understand this topic a lot better.