Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercises 1 to 8, except number 7. st::-NumberListO ListNode nodePtr = head ; wh

ID: 3903479 • Letter: E

Question

Exercises 1 to 8, except number 7.

st::-NumberListO ListNode nodePtr = head ; while (nodePtrnullptr) nextNode = nodePtr->next; nodePtr->next = nu 11 ptr; nodePtr nextNode Programming Challenges 1. Your Own Linked List ist class to hold a series of integers. The class should have destructor that tions for appending, inserting, and deleting nodes. Don't forget to add a tdestroys the list. Demonstrate the class with a driver program. 2. List Print function. Teated in Programming Challenge 1 to add a print nction. The function should display al the values in the linked list. Test the Modify the linked list class you Programn cl list out. Starting with an empty list, adding some elements, then printing the resulfting 3. List Copy Constructor Modify your linked list class of Programming Challenges 1 and 2 to add a copy con- structor. Test your class by making a list, making a copy of the list, then displaying the values in the copy. 4. List Reverse Modify the linked list class you created in the previous programming challenges by adding a member function named reverse that rearranges the nodes in the list so their order is reversed. Demonstrate the function in a simple driver program. Modify the linked list class you created in the previous programming challenges to include a member function named search that returns the position of a specific value, x, in the linked list. The first node in the list is at position 0, the second node is at posi- tion 1, and so on. If x is not found on the list, the search should return -1. Test the new member function using an appropriate driver program. 5. List Search

Explanation / Answer

#include<iostream>
using namespace std;
struct node
{
int a;
struct node *next;
}*head=NULL;
void insert(int x)
{
  
struct node *newnode=(struct node*)malloc(sizeof(struct node));
newnode->a=x;
newnode->next=NULL;
struct node *p=head;
if(head==NULL)
{
head=newnode;
}
else
{
while(p->next!=NULL)
{
p=p->next;
}
p->next=newnode;
}
cout<<"the element "<<x<<" is successfully inserted"<<endl;
}
void print()
{
cout<<"the elements in the linked list are"<<endl;
struct node *p=head;
while(p!=NULL)
{
cout<<p->a<<" ";
p=p->next;
}
cout<<endl;
}
void search(int x)
{
int count =0;
struct node *p=head;
while(p!=NULL)
{
if(p->a==x)
{
count++;
p=p->next;
cout<<"the element "<<x<<" is present in the linked list in the "<<(count+1)<<" position"<<endl;
return;
}
else
{
count=0;
p=p->next;
}
}
if(count==0){
cout<<"the element "<<x<<" is not present in the linked list"<<endl;
cout<<"-1"<<endl;
}
else
cout<<"the element "<<x<<" is present in the linked list"<<endl;
}
void reverse(struct node *head)
{
  
if(head==NULL)
return;
reverse(head->next);
cout<<head->a<<" ";
cout<<endl;
}

int main()
{
int pos;
insert(10);
insert(20);
insert(30);
insert(40);
insert(50);
print();
search(20);
search(60);
cout<<"the reversed linked list is"<<endl;
reverse(head);
  
  
return 0;
}

output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote