hola a todos, estoy tratando de hacer una insercion en una lista enlazada doble pero tengo error en la asignacion del puntero del nodo hacia el anterior, alguien me podria ayudar
#include <iostream>
#include <stdlib.h>
#include <conio.h>
struct nodo{
int nro;
struct nodo *sgte;
struct nodo *anterior;
};
typedef struct nodo *Tlista;
/*
----------------------------------------------
*/
void insertarFinal(Tlista &lista, int valor)
{
Tlista t, q = new(struct nodo);
q->nro = valor;
if(lista==NULL)
{
q->sgte = NULL;
q->anterior = lista;
lista = q;
}
else
{
t = lista;
while(t->sgte!=NULL)
{
t = t->sgte;
}
t->sgte = q;
q->anterior = t;
}
}
ya encontre el error, y queda asi
void insertarFinal(Tlista &lista, int valor)
{
Tlista t, q = new(struct nodo);
q->nro = valor;
q->estado = 1;
q->sgte = NULL;
if(lista==NULL)
{
q->anterior = lista;
lista = q;
}
else
{
t = lista;
while(t->sgte!=NULL)
{
t = t->sgte;
}
t->sgte = q;
q->anterior = t;
}
}