Solved

Doubly Linked Pointers

Posted on 2003-11-08
3
186 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Building cUrl in Windows v7.43.0 4 32
SendMessage fails while PostMessage works 2 114
Best book to learn C++ 4 79
passing data from one form to another form in c++ 27 80
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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 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