Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Doubly Linked Pointers

Posted on 2003-11-08
3
Medium Priority
?
190 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 90 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

719 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