Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How write this function in c++?cirucular header linked list #include using namespace std; struct node { int info; node *next; }; class clist { private:

How write this function in c++?cirucular header linked list
#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;
}
image text in transcribed
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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

Students also viewed these Databases questions