Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sequence::sequence(const sequence& source)
- {
- if (source.cursor == NULL)
- {
- list_copy(source.head_ptr, head_ptr, tail_ptr);
- cursor = NULL;
- precursor = NULL;
- }
- //the next two branch statements are the problem
- else if (source.cursor==source.head_ptr)
- {
- list_copy(source.head_ptr, head_ptr, tail_ptr);//copy the list
- cursor = head_ptr; //set cursor to the first node in the list
- precursor = NULL;//set the precursor to null
- }
- else
- {
- //divide the target list into two peices one starting at the head and ending at the precursor
- //the other starting with the cursor and ending at the tail node
- list_piece(source.head_ptr, source.cursor, head_ptr, precursor);
- list_piece(source.cursor, NULL, cursor, tail_ptr);
- //set the precursor's link to the cursor
- precursor->set_link(cursor);
- }
- ////////////////////////////////////
- many_nodes = source.many_nodes;
- return;
- }
- void sequence::operator =(const sequence& source){
- //check if the source sequence is the desitnation sequence
- if (this == &source)
- {
- return;
- }
- //if the list is empty
- if (source.many_nodes==0)
- {
- list_copy(source.head_ptr, head_ptr, tail_ptr);//copy the source list into the destination list
- cursor = NULL;//set cursor to null
- precursor = NULL;//set the precursor to null
- }
- //The next two branch statements is where the problem is
- else if (source.cursor==source.head_ptr)//if the list only has one element
- {
- list_copy(source.head_ptr, head_ptr, tail_ptr);//copy the source list into the destination list
- cursor = head_ptr;//set cursor to first element in list
- precursor = NULL;//set precursor to null
- }
- else//if the sequence has more than one element
- {
- //divide the target list into two peices one starting at the head and ending at the precursor
- //the other starting with the cursor and ending at the tail node
- list_piece(source.head_ptr, source.cursor, head_ptr, precursor);//
- list_piece(source.cursor, NULL, cursor, tail_ptr);
- //link the two peices together
- precursor->set_link(cursor);
- }
- //////////////////////////////////////
- many_nodes = source.many_nodes;
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement