Start New Discussion within our Software Development Community
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


That is, the first element is 5 and 35 is repeatedly added to obtain the next element (with wrap-around at 100).

What should my constructor wheel (); function definition be for it to do the above:

This is what i've tried to to:

wheel::wheel ()
  {
       wheel_ptr mover;
       arrow = new  wheel_node;
       arrow -> contents = 5;
       for ( mover = arrows -> cotents ; mover <100; mover = mover -> next)
      {
               arrow -> next = mover + 35;
     }
    if ( arrow -> next > 100 )
        arrow -> next = mover - 100;
 }

mover is a pointer to wheel_node and contents is an int You cannot equate them as you have done in Line 6.

In order to create the link list you have to allocate memory using the new operator to each node. You have done that only for the node arrow. Assuming that arrow is the first node you can create the link list in this way

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;

I have not tested it on my compiler.

This article has been dead for over six months. Start a new discussion instead.