Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 20, Problem 10PC
Program Plan Intro

MaxNode function

Program Plan:

“Main.cpp”:

  • Include the required header files.
  • Declare the necessary function prototype and constants.
  • Define the main () function.
    • Declare the necessary variables.
    • Insert the values into the list.
    • Displays to user that the values are inserted.
    • Call the method “maximumnode()” to find the largest element of the list.
    • The largest valued node gets displayed.

“NumberList.h”:

  • Define the template function necessary.
  • Define the class “NumberList”.
  • Declare the necessary structure variables.
  • Define the constructor and destructor.
  • Declare the necessary function prototype.

“NumberList.cpp”:

  • Include the required header files.
  • Declare the necessary function prototype and constants.
  • Define the method named “nodeappend()”,
    • Declare the necessary variables
    • Validate the list using if statement to find the status of the list.
    • Use loop to iterate for the contents present in the list and add node to the last of the list.
  • Define the method named “viewlist()”,
    • Declare the necessary variables.
    • Use loop that iterates to display the elements present in the list.
  • Define the method named “insertval()”,
    • Declare the necessary variables.
    • Validate the content of the list using if statement.
    • After evaluation of the list the contents the values are inserted at the desired location.
    • Loop is used to iterate for the values that are present, to validate whether the particular element is greater or lesser than the elements present in the list.
    • After evaluation the value is inserted at the desired location.
  • Define the method named “removenode()”,
    • Declare the necessary variables.
    • Validate the list using if statement in order to position the list based on the elements that is deleted from the list.
  • Define the method named “~NumberList()”,
    • Declare the necessary variables.
    • Loop that iterates to delete the memory allocates.
  • Define the method named “sortlist()”,
    • Declare the necessary variables.
    • Use loop to iterate for the value of the list.
    •  A condition statement to compare the elements of the list and return the sorted list.
  • Define the method named “mergeval()”,
    • Loop that is used to iterate to merge the values of the list based on the list values.
    • Call the function “sortlist()” to sort the value after being merged.
  • Define the method named “maximumnode()”,
    • Return the head node to be the maximum node.
  • Defined the method named “maxNode()”,
    • Use a condition statement to validate the elements of the list to identify the maximum value that is present in the list.

Blurred answer
Students have asked these similar questions
Q13.  Python function that takes two lists and returns True if they have at least one common member.
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.
def removeMultiples(x, arr) - directly remove the multiples of prime numbers (instead of just marking them) by creating a helper function. This recursive function takes in a number, n, and a list and returns a list that doesn’t contain the multiples of n.def createList(n) - a recursive function, createList(), that takes in the user input n and returns an array of integers from 2 through n (i.e. [2, 3, 4, …, n]). def Sieve_of_Eratosthenes(list) -  a recursive function that takes in a list and returns a list of prime numbers from the input list.Template below: def createList(n):    #Base Case/s    #ToDo: Add conditions here for base case/s    #if <condition> :        #return <value>      #Recursive Case/s    #ToDo: Add conditions here for your recursive case/s    #else:        #return <operation and recursive call>     #remove the line after this once all ToDo is completed    return [] def removeMultiples(x, arr):      #Base Case/s    #TODO: Add conditions here for your…
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