0

I made a program for a doubly circular linked list and in my first attempt, I created a struct for storing the values I need (info, and the pointers to the next/previous element). By doing that, it was simple to access the variables using instructions like     cin >> p->info or p->info = x or p->next = NULL, p->prev = NULL, p = p->next    and so on.
Then I read the homework more carefully and it said that the data should be private, so I replaced the "struct" with "class", declared those variables "private", then in order to access them, I found out that I should create some getters and setters. In the instructions down below you see that I created the getters, but how should I create the setters and how should I access the variables?

class node
{
private:

    int info;
    node *next,*prev;
public:
    int infoo() const
    {
        return info;
    }
    void setNode( int information )
    {
        info=information;
    }
    node *nextnode() const
    {
        return next;
    }
    node *prevnode() const
    {
        return prev;
    }
}*p,*first,*last,*firstt;

1 Answers1

0

It is simply:

void set_info(int aInfo)
    {
        info = aInfo;
    }
Jean-Marc Volle
  • 3,113
  • 1
  • 16
  • 20