0
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.

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Lerner
0

The spin could readily be represented by a loop that advances a pointer starting at a given location certain number of times.

I'm less certain how you will determine how many nodes there are to be in the wheel.

0

there are 20 nodes in this example, how would the loop look like

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.