Doubly linked list using dummy node.

HI all, I am creating a doubly circular linked list using dummy node. I have a variable "anchor" of type class, which I have to use in dummy node.

Following is my Data Structure .. Probably there could be some mistakes.
I am trying to create a new node in constructor but did not get success ! PLease suggest some idea. !

class My570List;

class My570ListElem
int data;
friend class My570List;
My570ListElem *next;
My570ListElem *prev;


class My570List


My570List *node;
//My570ListElem *p,*q;
int isempty();
void print();
void append(int data);
void remove(int data);
My570ListElem anchor;

node=new My570List();

Line -> node=new My570List();
This is keep on repeating when I saw in debugger ! I tried to create new inside the class .. that did not work; also tried to create outside the class and before constructor .. that wont work either. Segmentation Fault while creating the node.

Appreciate the quick response ! Thanks.
you cannot create an instance of the class itself in its constructor. It's an infinite recursion.
the constructor calls the constructor calls the consturctor...

avoid circular dependency. that's almost impossible to master
namespace My570{
   class List
      class Elem{/**/};
      Elem dummy;
Any Idea what is the way around to get this functionality .. Now I have create a new function as below.

int My570List::My570ListInit(My570List *node)

node=new My570List();
if(node==NULL) return FALSE;
(&(node->anchor))->next = (&(node->anchor));
(&(node->anchor))->prev = (&(node->anchor));
return TRUE;

Seems to be fine .. But I need the output as an address how will I get that .. !

here is main()

int main()
My570List disp;
My570List list;
list=new My570List();


I did not run this yet ... but doubtfull how this is goin to pass the address of achor to Append function !
You have a major design flaw. Your list contains a pointer to a list when it should have a pointer to a list element (node).
Last edited on
Yes and the pointer should be NULL instead of pointing to itself.
That's just a convention, using a `circular' list will prevent invalid pointers.
Besides, the dummy node approach will not use a pointer, but an object (the dummy)
Topic archived. No new replies allowed.