943,608 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1393
  • C++ RSS
Feb 28th, 2007
0

inserting a node befora certain node in doubly linklist

Expand Post »
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 :
C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
paeez is offline Offline
11 posts
since Feb 2007
Feb 28th, 2007
0

Re: inserting a node befora certain node in doubly linklist

what are the compiler errors?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Feb 28th, 2007
0

Re: inserting a node befora certain node in doubly linklist

it would be better if you can align your code first with respect to { and }
C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Structures and functions
Next Thread in C++ Forum Timeline: An equivalent method of substr() in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC