Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. sequence::sequence(const sequence& source)
  2. {
  3. if (source.cursor == NULL)
  4. {
  5. list_copy(source.head_ptr, head_ptr, tail_ptr);
  6. cursor = NULL;
  7. precursor = NULL;
  8. }
  9. //the next two branch statements are the problem
  10. else if (source.cursor==source.head_ptr)
  11. {
  12. list_copy(source.head_ptr, head_ptr, tail_ptr);//copy the list
  13. cursor = head_ptr; //set cursor to the first node in the list
  14. precursor = NULL;//set the precursor to null
  15. }
  16. else
  17. {
  18. //divide the target list into two peices one starting at the head and ending at the precursor
  19. //the other starting with the cursor and ending at the tail node
  20. list_piece(source.head_ptr, source.cursor, head_ptr, precursor);
  21. list_piece(source.cursor, NULL, cursor, tail_ptr);
  22. //set the precursor's link to the cursor
  23. precursor->set_link(cursor);
  24. }
  25. ////////////////////////////////////
  26. many_nodes = source.many_nodes;
  27. return;
  28.  
  29. }
  30.  
  31. void sequence::operator =(const sequence& source){
  32. //check if the source sequence is the desitnation sequence
  33. if (this == &source)
  34. {
  35. return;
  36. }
  37. //if the list is empty
  38. if (source.many_nodes==0)
  39. {
  40. list_copy(source.head_ptr, head_ptr, tail_ptr);//copy the source list into the destination list
  41. cursor = NULL;//set cursor to null
  42. precursor = NULL;//set the precursor to null
  43. }
  44. //The next two branch statements is where the problem is
  45. else if (source.cursor==source.head_ptr)//if the list only has one element
  46. {
  47. list_copy(source.head_ptr, head_ptr, tail_ptr);//copy the source list into the destination list
  48. cursor = head_ptr;//set cursor to first element in list
  49. precursor = NULL;//set precursor to null
  50. }
  51. else//if the sequence has more than one element
  52. {
  53. //divide the target list into two peices one starting at the head and ending at the precursor
  54. //the other starting with the cursor and ending at the tail node
  55. list_piece(source.head_ptr, source.cursor, head_ptr, precursor);//
  56. list_piece(source.cursor, NULL, cursor, tail_ptr);
  57. //link the two peices together
  58. precursor->set_link(cursor);
  59. }
  60. //////////////////////////////////////
  61. many_nodes = source.many_nodes;
  62. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement