Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Doubly linked list

Posted on 2003-11-07
10
258 Views
Last Modified: 2011-09-20
Why do we refer to say
C = cur->prev->next  

instead of just saying

C = cur

for given 3 nodes A,B & C in a doubly circular sorted linked list.

If I am incorrect then please clearify what does one mean by
cur->prev->next  given that 3 nodes were given node A,B & C.
0
Comment
Question by:Mallp
  • 5
  • 3
10 Comments
 
LVL 9

Expert Comment

by:tinchos
ID: 9703523
I would say that it's just the same.

If you post a code using that, maybe I can help you a little more.

Tincho
0
 

Author Comment

by:Mallp
ID: 9704197
Here is an example.

void SpecializedList::InsertEnd(int item)
{
      struct node *temp = get_node(item);
      temp->info = item;
      if (head==NULL)
      {       head = temp;                  // head is assigned the value of temp.
            head->prev = temp;            
            head->next = temp;
            temp->prev = head;
            temp->next = head;
            tail = temp;                  // head is also a tail if only one node exists.
      }
      else
      {      
            cur=head;
            while (cur->next != head)
                  cur=cur->next;
            temp->prev = head->prev;
            temp->next = head;
            head->prev->next = temp;
            head->prev = temp;
            tail=temp;
      }
}

0
 
LVL 9

Expert Comment

by:tinchos
ID: 9704611
Then Mallp

I would say that it's just the same, but I would say that it's just a matter of coding style

It may be clearer to the person who wrote it.

Tincho
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 15

Accepted Solution

by:
efn earned 20 total points
ID: 9705722
Your question and your example are different.  In the form in the question, they are the same, assuming the list is properly linked.  But in the example, the code makes sense, and the substitution would not make sense.  I'll try to explain it.

You have a circular list, so at the start the tail is linked to the head:

tail -> head
tail <- head

The code is inserting the node addressed by temp between tail and head.  The first thing it does is set the pointers in temp:

          temp->prev = head->prev;
          temp->next = head;

So then we have:

tail -> head
tail <- head
tail <- temp
temp -> head

So now temp has the right pointers, but we need to change the forward pointer in tail and the backward pointer in head.  The next line changes the forward pointer in tail.

head->prev->next = temp;

So then we have

tail -> temp
tail <- head
tail <- temp
temp -> head

The old value of head->prev->next is indeed head, but we are not using the value here, we are changing it:  we are referring to head->prev->next in order to change it.  So it makes sense and definitely does not have the same effect as

head = temp;

At the risk of running the point into the ground, I'll give a non-pointer example.  If you had

a = 5;
b = a;

you could just as well code

b = 5;

but if you have

a = 5;
a = 10;

you can't just as well code

5 = 10;

--efn
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10242612
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in approximately one week.  I would appreciate any comments by the experts that would help me in making a recommendation.

It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
http://www.experts-exchange.com/help.jsp#hs5

Tinchos
EE Cleanup Volunteer
0
 
LVL 15

Expert Comment

by:efn
ID: 10242836
I think I answered it.

--efn
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10243063
efn

I didn't post a recommendation for this as I'm directly involved in it and personally I would rather avoid judging the questions I participated in unless the recommendation is fairly clear to me.
I just posted the message just waiting for the asker to close his question.

Lets wait to see if he shows up and if that does not happen I'll post a recommendation for it.

Tincho
0
 
LVL 15

Expert Comment

by:efn
ID: 10243195
Tincho,

OK, no problem, thanks for your cleanup efforts.

--efn
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10286282
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: efn {http:#9705722}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question