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
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…
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.
True or False The objects of a class can be stored in an array, but not in a 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
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr