Ring
Ring class, with iterators
Code
template <typename Key, typename Info>
class Ring
{
// with iterator
// double-linked
}
Info
Ring class, with iterator
!!! Ownership of iterator !!!
General purpose class, not only for the final testing function
Minimum number of method without losing flexibility
Iterator used for parameter of pointing to the place
Ring of:
1 2 3 4 5 1 2 1 2 1 3 5
The 4th 2 should get the marked one (loops around)
no sentinels
Testing
External (not friend) function - no access to private parts of the class
template <typename Key, typename Info>
Ring <Key, Info> shuffle (const Ring <Key, Info>& r1, int start1, int len1,
const Ring <Key, Info>& r2, int start2, int len2,
int limit);
limit - number of elements which should be in the output Ring
start - offset from Node pointer by ring.any (can be positive and negative)
len - number of consecutive Nodes from r1/r2 to be copied into the output (can be +/-)
what if len == 0? - output an empty ring
Example
r1 - 1 2 3 4 5
r2 - A B C D
shuffle (r1, 2, 3, r2, -1, -2, 11);
output - 3 4 5 D C 1 2 3 B A 3
3's in the output are copies of the same node from r1## Lab 2