struct wheel_node
{
int contents;
wheel_node* next;
};
typedef wheel_node* wheel_ptr;
class wheel
{
private:
wheel_ptr arrow;
public:
wheel ();
void print ();
void spin (int distance);
void move_to (int number);
};
The constructor wheel creates a circular linked list as follows:
arrow -> 5 -> 40 -> 75 -> 10 -> 45 -> 80-> 15 … 70
the first element is 5 and 35 is repeatedly added to obtain the next element (with wrap-around at 100).
heres what i got for the wheel () function:
wheel::wheel ()
{
wheel_ptr mover,last;
arrow = new wheel_node;
arrow -> contents = 5;
arrow->next=NULL;
last=arrow;
for ( int i = arrows -> cotents+35 ; i <100; i=i+35)
{
mover=new wheel_node;
mover->contents=i;
mover->next=NULL;
last->next=mover;
}
last->next=arrow;
}
What would the void spin (int distance) function definition be for it to spin the wheel with a given distance. It basically moves the arrow pointer the given number of nodes. Thus, if spin was called with 2, arrow would move ahead to point at the 75 node.