for c++ please thank you  please type the code so i can copy and paste easily thanks. 4, List search  Modify the linked listv class you created in the previous programming challange to include a member function named search that returns the position of a specific value, x, in the lined list. the first node in the list is at position 0, the second node is at position 1, and so on. if x is not found on the list, the search should return -1 test the new member function using an approprate driver program. here is my previous programming challange.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

for c++ please thank you 

please type the code so i can copy and paste easily thanks.

4, List search 

Modify the linked listv class you created in the previous programming challange to include a member function named search that returns the position of a specific value, x, in the lined list. the first node in the list is at position 0, the second node is at position 1, and so on. if x is not found on the list, the search should return -1 test the new member function using an approprate driver program.

here is my previous programming challange.

#include <iostream>

using namespace std;

struct node

{

int data;

node *next;

};

class list

{

private:

node *head,*tail;

public:

list()

{

head = NULL;

tail = NULL;

}

~list()

{

  

}

void append()

{

int value;

cout<<"Enter the value to append: ";

cin>>value;

node *temp=new node;

node *s;

temp->data = value;

temp->next = NULL;

s = head;

if(head==NULL)

head=temp;

else

{

while (s->next != NULL)

s = s->next;

s->next = temp;

}

}

void insert()

{

int value,pos,i,count=0;

cout<<"Enter the value to be inserted: ";

cin>>value;

node *temp=new node;

node *s, *ptr;

temp->data = value;

temp->next = NULL;

cout<<"Enter the postion at which node to be inserted: ";

cin>>pos;

s = head;

while (s!=NULL)

{

s = s->next;

count++;

}

if (pos==1)

{

if(head==NULL)

{

head=temp;

head->next=NULL;

}

else

{

ptr=head;

head=temp;

head->next=ptr;

}

}

else if(pos>1 && pos<=count)

{

s=head;

for(i=1;i<pos;i++)

{

ptr=s;

s=s->next;

}

ptr->next=temp;

temp->next=s;

}

else

cout<<"Positon out of range"<<endl;

}

void deleting()

{

int pos,i,count=0;

if (head==NULL)

{

cout<<"List is empty"<<endl;

return;

}

cout<<"Enter the position of value to be deleted: ";

cin>>pos;

node *s,*ptr;

s=head;

if(pos==1)

head=s->next;

else

{

while(s!=NULL)

{

s=s->next;

count++;

}

if(pos>0 && pos<=count)

{

s=head;

for(i=1;i<pos;i++)

{

ptr=s;

s=s->next;

}

ptr->next=s->next;

}

else

cout<<"Position out of range"<<endl;

free(s);

cout<<"Element Deleted"<<endl;

}

}

void display()

{

node *temp;

if(head==NULL)

{

cout<<"The List is Empty"<<endl;

return;

}

temp=head;

cout<<"Elements of list are: "<<endl;

while(temp->next!=NULL)

{

cout<<temp->data<<"->";

temp = temp->next;

}

cout<<temp->data<<endl;

}

};

int main()

{

list s;

s.append();

s.append();

s.append();

s.append();

s.display();

s.insert();

s.display();

s.append();

s.display();

s.deleting();

s.display();

return 0;

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education