Bueno este algoritmo Logra crear una lista que se puede recorrer de un lado al otro utilizando un solo puntero, guardando en el la direccion relativa entre un nodo y otro utilizando xord.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
/* Definicion de estructuras */
typedef struct lista
{
struct nodo *REAR;
struct nodo *FRONT;
}lista;
typedef struct nodo
{
struct nodo *LINK;
char DATO[80];
}nodo;
/* Definicion de Funciones */
void altas(struct lista &l,char *DATO)
{
struct nodo *DIR;
DIR = new nodo;
if (l.REAR != NULL)
{
l.REAR->LINK =(struct nodo *)(((int) l.REAR->LINK) ^ ((int)DIR)); // hacemos un xord de las direcciones de los nodos.
}
else {
l.FRONT = DIR;
}
strcpy(DIR->DATO,DATO);
DIR->LINK = l.REAR;
l.REAR = DIR;
}
void Recorre_de_atras (struct lista &l)
{
if (l.REAR != NULL) {
struct nodo *p;
struct nodo *q;
struct nodo *x;
p = l.REAR;
q = NULL;
printf("Dir Relativa: %x Dato: %s \n",p,p->DATO);
do {
x = p;
p =(struct nodo *)(((int) p->LINK) ^ ((int)q));;
printf("Dir Relativa: %x Dato: %s \n",p,p->DATO);
q = x;
} while (p != l.FRONT);
}
}
void Recorre_de_adelante (struct lista &l)
{
if (l.FRONT != NULL) {
struct nodo *p;
struct nodo *q;
struct nodo *x;
p = l.FRONT;
q = NULL;
printf("Dir Relativa: %x Dato: %s \n",p,p->DATO);
do {
x = p;
p =(struct nodo *)(((int) p->LINK) ^ ((int)q));;
printf("Dir Relativa: %x Dato: %s \n",p,p->DATO);
q = x;
} while (p != l.REAR);
}
}
int main ()
{
struct lista l;
char ch[80];
l.REAR = NULL;
l.FRONT = NULL;
printf("%s\n","Ingrese Datos (fin para terminar)");
fgets(ch,80,stdin);
while (strncmp(ch,"fin",3)) {
altas(l,ch);
fgets(ch,80,stdin);
}
//system("clear"); //Sistema Operativo unix
//system("cls"); //Sistema Operativo DOS
printf("%s\n","Recorrido Hacia Atras");
Recorre_de_atras(l);
printf("%s\n","Recorrido Hacia delante");
Recorre_de_adelante(l);
return 0;
}
Espero q les sirva, saludos.