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.

Recommended Answers

All 3 Replies

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.

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

int spinDistance = 2;
for(int i = 0; i < spinDistance; ++i)
++arrow;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.