STARTING OUT WITH C++ MPL
STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
bartleby

Concept explainers

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

Recursive Member Check

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 destructor to check whether the data value entered is a member function or not is defined “bool isMember(double x){ return rIsMember(head, x);}~LinkedList()”.
    • 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.
    • Check whether the data value entered is a member of the link list or not by calling “list1.isMember(x)” function.
      • If the data value entered is present within the link list, it prints member, else it prints not member.

Blurred answer
Students have asked these similar questions
5. List Member Deletion Modify the list class you created in the previous programming challenges by adding a function to remove an item from the ist and by adding a destructor: void zemove (double x) : Linkedtist (02 Test the class by adding a sequence of instructions that mixes operations for adding items, removing items, and printing the list.
c++ data structures ADT Unsorted List The specifications for the Unsorted List ADT states that the item to be deleted is in the list.   Rewrite the specifications for DeleteItem so that the list is unchanged if the item to be deleted is not in the list. Rewrite the specifications for DeleteItem so that all copies of the item to be deleted are removed if they exist
Data structure & Algorithum java program 1) Add a constructor to the class "AList" that creates a list from a given array of objects.2) Add a method "getPosition" to the "AList" class that returns the position of a given object in the list. The header of the method is as follows : public int getPosition(T anObject)3) Write a program that thoroughly tests all the methods in the class "AList".4) Include comments to all source code.
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
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr