Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Where is the error I want to fix my code the linked list is circular #include using namespace std; struct node { int info; node
Where is the error I want to fix my code the linked list is circular #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) { node*p=new node; p->info=item; node*per=head; for(node*curr=head->next;curr!=head;curr=curr->next){ per=curr; per=per->next; curr->next=p; p->next=per; } { if(head->next==head){ p->next=head; head->next=p;} } } void change (int value) { node*curr=head->next; if(curr->next!=head){ curr=curr->next; curr->info=8; } } }; 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 list after adding the third value ' 6 463
Where is the error I want to fix my code
the linked list is circular
#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)
{ node*p=new node;
p->info=item;
node*per=head;
for(node*curr=head->next;curr!=head;curr=curr->next){
per=curr;
per=per->next;
curr->next=p;
p->next=per; }
{
if(head->next==head){
p->next=head;
head->next=p;}
}
}
void change (int value)
{ node*curr=head->next;
if(curr->next!=head){
curr=curr->next;
curr->info=8;
}
}
};
int main()
{
clist s;
s.add(4);
cout
s.traverse();
s.add(3);
cout The list after adding the third value ' 6 463
s.traverse();
s.add(6);
cout
s.traverse();
s.change(8);
cout
s.traverse();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started