inserting a node befora certain node in doubly linklist

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2007
Posts: 7
Reputation: paeez is an unknown quantity at this point 
Solved Threads: 0
paeez paeez is offline Offline
Newbie Poster

inserting a node befora certain node in doubly linklist

 
0
  #1
Feb 28th, 2007
iv written a code that insert a node befor a node containing a certain value(for example insert a node having value 3,befor the node containing value5),i checked the code many times,i couldnt find any mistake, but the compiler errors this part. can any one help.
here is the code :
  1. void insert_b4_search(int ai,int bj)// ai is the value we are looking for in the linklist . bi is the value od the new node
  2. { node *temp;
  3. temp = head;
  4. while(temp != NULL && temp-> num != ai)//num=value
  5. {temp = temp -> nxt;
  6. if(temp == NULL){
  7. cout<<"ooo"<<endl;
  8. } }
  9. if (temp == head){
  10. insert_at_first(bj);//call add at first method
  11. }
  12. else if(temp == tail){
  13. insert_to_tail(bj);
  14. }
  15. else { ptr = new node(bj,NULL,NULL);
  16. ptr->prev = new node(bj, ptr->prev, ptr);
  17. ptr->prev->prev->next = ptr->prev;
  18. }
  19. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,401
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: inserting a node befora certain node in doubly linklist

 
0
  #2
Feb 28th, 2007
what are the compiler errors?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,827
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 118
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: inserting a node befora certain node in doubly linklist

 
0
  #3
Feb 28th, 2007
it would be better if you can align your code first with respect to { and }
  1. )// ai is the value we are looking for in the linklist . bi is the value od the new node
Is this one line or 2 line
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC