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
Exercise, maxCylinderVolume F# system function such as min or methods in the list module such as List.map are not allowed Write a function maxCylinderVolume that takes a list of floating-point tuples that represent dimensions of a cylinder and returns the volume of the cylinder that has the largest volume. Each tuple has two floating point values that are both greater than zero. The first value is the radius r and the second value is the height h. The volume of the cylinder is computed using ??2h. The value π is represented in F# with System.Math.PI. If the list is empty, return 0.0. Examples: > maxCylinderVolume [(2.1, 3.4); (4.7, 2.8); (0.9, 6.1); (3.2, 5.4)];;val it : float = 194.3137888> maxCylinderVolume [(0.33, 0.66)];;val it : float = 0.2257988304
7. Dynamic MathStack The MathStack class shown in this chapter has only two member functions: add and sub. Write the following additional member functions: Function Description mult Pops the top two values off the stack, multiplies them, and pushes their product onto the stack. div Pops the top two values off the stack, divides the second value by the first, and pushes the quotient onto the stack. addAll Pops all values off the stack, adds them, and pushes their sum onto the stack. multA11 Pops all values off the stack, multiplies them, and pushes their prod- uct onto the stack. Demonstrate the class with a driver program. here is the extention file please use it. // Specification file for the IntStack class #ifndef INTSTACK_H #define INTSTACK_H   class IntStack { private:    int *stackArray;  // Pointer to the stack array    int stackSize;    // The stack size    int top;          // Indicates the top of the stack   public:    // Constructor    IntStack(int);      // Copy constructor…
Count dominators def count_dominators(items): An element of items is said to be a dominator if every element to its right (not just the one element that is immediately to its right) is strictly smaller than it. By this definition, the last item of the list is automatically a dominator. This function should count how many elements in items are dominators, and return that count. For example, dominators of [42, 7, 12, 9, 13, 5] would be the elements 42, 13 and 5. Before starting to write code for this function, you should consult the parable of "Shlemiel the painter" and think how this seemingly silly tale from a simpler time relates to today's computational problems performed on lists, strings and other sequences. This problem will be the first of many that you will encounter during and after this course to illustrate the important principle of using only one loop to achieve in a tiny fraction of time the same end result that Shlemiel achieves with two nested loops. Your workload…
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