Question: The following program stores a list of integer numbers dynamically through a circular header linked list in c++, complete it by defining the following functions:
The following program stores a list of integer numbers dynamically through a circular header linked list in c++, complete it by defining the following functions:
1- void add (int item);
This function inserts a new node after the first node (when the list is empty, the inserted node will be the first node).
2- void change (int value);
This function used to change the value of the last node to value.
#include
using namespace std;
struct node
{ int info;
node *next;
};
class clist
{
private:
node *head;
public:
clist(){head=new node; head->next=head;}
void traverse()
{
if(head->next==head)
cout
else
{
node*curr=head->next;
while(curr!=head)
{
coutinfo
curr=curr->next;
}
cout
}
}
void add(int item)
{
}
void change (int value)
{
}
};
int main()
{
clist s;
s.add(4);
cout
s.traverse();
s.add(3);
cout
s.traverse();
s.add(6);
cout
s.traverse();
s.change(8);
cout
s.traverse();
return 0;
}
The Output will be as the following:

The list after adding the first value ' 4 ' 4 The list after adding the second value ' 3 ' 43 The list after adding the third value ' 6 ' : 463 The list after calling 'change' function with parameter ' 8 ' : 468 Program ended with exit code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
