I believe I got most of them correct, except there's a strange problem with my copy constructor and assignment operator. I tried my best to debug this problem and I found that the advance() method (move cursor and precursor to next) does not work for strange reason, and it only appears in copy constructor and assignment operator (I cout current() before and after advance(), and it does not work). I might be wrong though.
I would really like to know if I'm on the right track, and what's the problem behind this bug. I appreciate any feedback from you. Thanks!
seq_ex3.cpp:116:29: error: declaration of ‘void operator delete(void*)’ has a different exception specifier
/usr/include/c++/4.9.0/new:132:6: error: from previous declaration ‘void operator delete(void*) noexcept’
sequence3.cpp: In member function ‘main_savitch_5::sequence::value_type main_savitch_5::sequence::current() const’:
sequence3.cpp:146:1: warning: control reaches end of non-void function
> I found that the advance() method does not work for strange reason,
> and it only appears in copy constructor and assignment operator
I need a better description than `does not work'
Also, `advance()' is used in other tests and in the `correct()' function.
> the file is rather lengthy
learn to isolate the problem. ¿which test number is the one giving issue? ¿do I need to run the previous tests in order to reproduce the problem?
> I cout current() before and after advance(), and it does not work
¿do you realize the amount of output that your program has?
¿how do you expect us to find that "debug" output? At least use a different stream (like cerr or clog, or a file)
I did some additional test last night, and I'm sure the problem was with my constructor and =operator, however, not with the advance() method. for some reason, whenever I copy the linked-list sequence when cursor is at the beginning of the sequence, it copies one extra first element.
for instance,
sequence original is {1,2,3,4,5,6,7}
sequence copy(original)
copy is {1,1,2,3,4,5,6,7}
and the cursor stay with the second 1.
thanks for helping me out, I'll try to go through the logic again to see if i was missing anything.
void list_copy(const node* source_ptr, node*& head_ptr, node*& tail_ptr)
{
//...
list_head_insert(head_ptr, source_ptr->data()); //first insertion
tail_ptr = head_ptr;
//source_ptr keeps pointing to the same location
// Copy the rest of the nodes one at a time, adding at the tail of new list.
while (source_ptr != NULL)
{
list_insert(tail_ptr, source_ptr->data()); //second insertion
tail_ptr = tail_ptr->link();
source_ptr = source_ptr->link();
}
}
Using a circular list with header cell would avoid having to code all those especial cases.