Solved

Doubly Linked Pointers

Posted on 2003-11-08
3
185 Views
Last Modified: 2010-04-01
Hello,

I am trying to insert a new node into a doubly linked list before the node pointed to by Cur.

I have the following but i am not sure if i am right. Please advise.

P->next=cur;
P->before=cur->before;
P->before->next=P;
P->next->before=P;

thanks

0
Comment
Question by:Gipsy
3 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 30 total points
ID: 9706533
this section of the code looks correct
0
 
LVL 22

Expert Comment

by:grg99
ID: 9706985
Looks okay.  For total safety, I'd replace the equals sign with a macro that does the assignment but also checks for null pointers and a valid node password.  When I write this kind of code, I usually get tripped up at leastra couple times before all the erors are filtered out.   Something like:

#define CarefulAssign(x) ((x)==NULL || (x)->pw != ThePw ? NULL, printf("bad assign of ##x## at line __LINE__!!\n" ): (x) )


Regards,

grg99

0
 
LVL 9

Expert Comment

by:tinchos
ID: 10242623
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: sunnycoder {http:#9706533}

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

896 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now