Starting out With C++, Early Objects - Access
Starting out With C++, Early Objects - Access
8th Edition
ISBN: 9780133452259
Author: GADDIS
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 17, Problem 7PC
Program Plan Intro

List Search

Program Plan:

  • Include the required specifications into the program.
  • Declare a class ListNode.
    • Declare the member variables “value” and “*p” in structure named “ListNode”.
    • The data value of node is stored in variable v and address to next pointer is stored in pointer p.
    • Declare the constructor, destructor, and member functions in the class.
    • Declare the structure variable “next” and a friend class Linked List.
  • Declare a class LinkList.
    • Function to insert elements into the linked list “void add(double n)”is defined.
    • Function to check whether a particular node with a data value n is a part of linked list or not “bool isMember(double n)”.
    • A recursive print method is defined to print all the data values present in the link list “void rPrint()”.
    • A method to search for an element present in the link list called “int LinkedList::search(double x)” is called that returns the position of the element present in the link list.
    • A destructor is called to delete the desired data value entered by the user called   “LinkedList::~LinkedList( )”.
    • A method to remove the element passed as a parameter from the link list is called “void LinkedList::remove(double x)”.
    • Declare a method “void reverse( )”  to reverse the elements present in the link list by traversing through the list and Move node at end to the beginning of the new reverse list being constructed.
    • Declaration of structure variable head to store the first node of the list “ListNode * head” is defined.
    • A function “void LinkedList::add(double n)” is defined which adds or inserts new nodes into the link list.
    • A function “bool LinkedList::isMember(double n)” is defined which  searches for a given data value within the nodes present in the link list.
    • A destructor “LinkedList::~LinkedList()” deallocates the memory for the link list.
    • A function “void LinkedList::print()” is used to print all the node data values present in the link list by traversing through each nodes in the link list.
    • A recursive member function check is defined called “bool LinkedList::rIsMember(ListNode *pList,double x)” .
      • If the data value entered is present within the link list, it returns true, else it returns false.
  • Declare the main class.
    • Create an empty list to enter the data values into the list.
    • Copy is done using copy constructor.
    • Input “5” numbers from user and insert the data values into the link list calling “void LinkedList::add(double n)” function.
    • Print the data values of the nodes present in the link list.
    • “int LinkedList::search(double x)” function is called to search the element present in the link list and prints the position of the element.

Blurred answer
Students have asked these similar questions
Write a struct Student that has member variables: (string) first name, (int) age and (double) fee. Write the functions as described in the class for the following purposes.1. Write a c++ function to create a dynamic sorted (in ascending order according to the age)doubly linked list, where the data component of each node is an instance of the structStudent.2. Write a function to insert the instances in the linked list. You also need to write a function to find the spot for insertion of the nodes.3. Write a function to remove the node from the linked list.4. Write a function to count the elements of the linked list.5. Write a function to determine check whether an element belongs to the linked list.6. Write a function to print the linked list (from head node) on the console.7. Write a function to print the linked list (from tail node) on the console. Implement the above functions as follows.Initially, the list must have five nodes that are the instances of the struct whose member…
Write a struct ‘Student’ that has member variables: (string) first name, (int) age and (double) fee. Create a sorted (in ascending order according to the age) linked list of three instances of the struct Student. The age of the students must be 21, 24 and 27. Write a function to insert the new instances (elements of the linked list), and insert three instance whose member variable have age (i) 20, (ii) 23 and (iii) 29. Write a function to remove the instances from the linked list, and remove the instances whose member variables have age (i) 21 and (ii) 29. Write a function to count the elements of the linked list. Write a function to search the elements from the linked list, and implement the function to search an element whose age is 23. Write a function to print the linked list on the console. Consider the Student struct as defined above. Create a stack of 5objects of the class. Implement the following (i) push an element to the stack (ii) pop an element from the stack (iii) get the…
HELP Write C code that implements a soccer team as a linked list. 1. Each node in the linkedlist should be a member of the team and should contain the following information: What position they play whether they are the captain or not Their pay 2. Write a function that adds a new members  to this linkedlist at the end of the list.
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning