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 8PC
Program Plan Intro

Member Insertion by Position

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 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 link list method to insert elements into the link list called “void LinkedList::insert(double x, int pos)” is called that insert elements into the link list at specific positions.
    • 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
C++ function Linked list   Write a function, to be included in an unsorted linked list class, called replaceItem, that will receive two parameters, one called olditem, the other called new item. The function will replace all occurrences of old item with new item (if old item exists !!) and it will return the number of replacements done.
C++ Programming Language ::::::: Redo the same functions this time as nonmember functions please : NOTE: You can add only one function into the linked list class get_at_position which will return value of element at given position. 1) Insert before tail :  Insert a value into a simply linked list, such that it's location will be before tail. So if a list contains {1, 2, 3}, insert before tail value 9 is called, the list will become {1, 2, 9, 3}. 2) Insert before value :  Insert a value into a simply linked list, such that it's location will be before a particular value. So if a list contains {1, 2, 3}, insert before 2 value 9 is called, the list will become {1, 9, 2, 3}. 3)Count common elements : Count common values between two simply linked lists.So if a list1 contains {1, 2, 3, 4, 5}, and list2 contains {1, 3, 4, 6}, number of common elements is 3. 4) Check if sorted : Check if elements of simply linked lists are sorted in ascending order or not.So if a list contains {1, 3, 7, 8, 9}…
Arithmetic progression def arithmetic_progression(items): An arithmetic progression is a numerical sequence so that the stride between each two consecutive elements is constant throughout the sequence. For example, [4, 8, 12, 16, 20] is an arithmetic progression of length 5, starting from the value 4 with a stride of 4.Given a non-empty list items of positive integers in strictly ascending order, find and return the longest arithmetic progression whose all values exist somewhere in that sequence. Return the answer as a tuple (start, stride, n) of the values that define the progression. To ensure unique results to facilitate automated testing, if there exist several progressions of the same length, this function should return the one with the lowest start. If several progressions of equal length emanate from the lowest start, return the progression with the smallest stride. items  Expected result [42] (42, 0, 1) [2, 4, 6, 7, 8, 12, 17] (2, 2, 4) [1, 2, 36, 49, 50, 70, 75, 98,…
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
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage