Solved

Doubly Linked Pointers

Posted on 2003-11-08
3
189 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
[X]
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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

636 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