• 10-13-2005, 01:32 PM
Qatar
few Qs. on circular doubly linked list
Hello ..

I've got some Qs.

assume that we have this Doubly linked list

what will happened if we apply the following ?

1- list->next->next->next=list->prev

and then we apply to the new list

2- list->prev->prev->prev=list->next->next->next->prev

and then ..

3- list->next->next->next->prev=list->prev->prev->prev

and then..

4- list->next=list->next->next

and finally ..

5- list->next->prev->next=list->next->next->next

thank you
• 10-13-2005, 02:10 PM
Danny
First of all, if you read the forum's Etiquette you would know that we don't do homework assignments here, unless you show a real effort to solve the problem by yourself (which doesn't seem to be the case). Secondly, you need to define the loose terms: what's list->next exactly? Does it refer to thr first node of the list or to recentlt traversed node?
When you know the answer to this simple question, you'll be able to solve the rest of the exam. Simply take a pencil and follow the nodes according to the directions in the each question. It really isn't difficult.
• 10-15-2005, 04:04 AM
Qatar
Hello Mr. Danny The Moderator..
First of all thank you for replying !

Well, This is not a homework ! This is an exercise to improve my skills !
and I faced some difficulties in solving it because this is the first ADT course for me and even the Dr. didn't teach us doubly linked list ..

It seems that it is so easy to you ,But it is not so for me .. that is why I post it here .. to get a help !

Well, Mr. Danny ,
I think that it was better if you didn't reply in that way without any help not even a hint !
We are here to learn from each other .. not to refuse helping each other !

thank you very much ..
• 10-15-2005, 05:48 AM
Qatar,
why else would he bother to ask you to clarify ->?
• 10-15-2005, 06:16 AM
Qatar
this is my trial..

# include<iostream.h>

class node{
public:
int data;
node *next,*prev;
node(){ next=prev=0;}
node( int d,node *ptr1=0,node *ptr2=0)
{data=d;
next=ptr1;
prev=ptr2;
}

};

class list {
public:
void print();
void one();
void two();

private:

};

{
if(tail==0)
else
}

{
if(tail==0)
{
tail->next= new node (d,0,tail);
tail=tail->next;
}
else

}

void list::print()
{
while(p!=0)
{
cout<<p->data<<" ";
p=p->next;
}
}

void list::one()
{

}

void list::two()
{

}

void main()
{

list l;

l.print();
cout<<endl;
l.print();
cout<<endl;
l.print();
cout<<endl;
l.print();
cout<<endl;
l.print();
cout<<endl;

l.one();
l.print();
cout<<endl;

l.two();
l.print();
cout<<endl;

}

------------------------------------------------------

I tried to do it that way ..
the secound method ( two(); )
doesn't work ..

I don't know what the prob. is !
• 10-15-2005, 09:24 AM
Danny
what exactly isn't working? does the code compile? If it doesn't, which error message are you getting? If it crashes at runtime, please say where exactly the crash occurs.
• 10-15-2005, 09:42 AM
Danny
Quote:

Originally Posted by Qatar
,
I think that it was better if you didn't reply in that way without any help not even a hint !
We are here to learn from each other .. not to refuse helping each other !

thank you very much ..

Actaully, my reply included more than a hint. Anyway, your second post does include what is considered to be "an effort on yoru side" (see my other reply below).
• 10-15-2005, 01:51 PM
jonnin
class node
{
public:
int data;
node *next,*prev;
node(){next=prev=0;}

---node( int d,node *ptr1=0,node *ptr2=0)
---{data=d;
---next=ptr1;
--- prev=ptr2;
}

---node( int d,node *ptr1=0,node *ptr2=0)
If this compiles, what is it supposed to do? You clear the pointers when you try
to create a node from good data? I am not sure what the result of this will be but it looks wrong ... Danny? ... consider his usage :

{
• 10-15-2005, 05:15 PM
Qatar
thank you Danny .. Thank you very much ..
Quote:

void list::two()
{

}
I've got a prob. here ..
it is keep running without stopping !!
I'm not sure of my implemintation ..

-------------------------------------------------

Jonnin ,
Quote:

node( int d,node *ptr1=0,node *ptr2=0)
Yes , it is compile .. this is a constructor ..

..
.

Quote:

{
it creates a new node d .. next pointer is pointed to head and the previous pointed to 0
• 10-17-2005, 08:46 AM
jonnin
If its running without stopping and the only while loop is in the print statement, then remove the print first. If it still does not stop, you have a pointer problem and the app is hung (unlikely to to this without a crash). Let me know if removal of the print creates a program that stops.
• 10-17-2005, 01:41 PM
Qatar
I've end up with this answer ..

Is it okay ?!
• 10-26-2005, 07:06 AM
Qatar
I've got a full mark :D
• 10-26-2005, 09:54 AM
Danny
wonderful!