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 I have at the moment from 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 get this error:
It only gives me the error when I try to point the left variable (of type node) of the third node, to the variable data (of type int) 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 pointer concept correctly, and I think that by seeing this exercise solved I will understand this topic much better.
If
dato
it's an integer, you can't assign it to a pointer.What you want to do, initialize the list, is very simple
Questions about pointers there are quite a few on the site. You can consult them, to see various and varied examples.
Try changing the periods (.) that appear in the errors by arrow (->)
arrow operator
Arrows page in english
Pointer operators in Spanish