Solved

Doubly Linked Pointers

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

708 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

18 Experts available now in Live!

Get 1:1 Help Now