Solved

Doubly linked list

Posted on 2003-11-07
10
257 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ to C# code conversion issue 4 108
Microsoft C++ code failing in executable that worked 9 101
C++ mouse_event mouse look 7 83
Copy output image from TWindowsMediaPlayer 6 42
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

803 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