EBK STARTING OUT WITH C++
EBK STARTING OUT WITH C++
9th Edition
ISBN: 9780134996066
Author: GADDIS
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
bartleby

Concept explainers

Question
Book Icon
Chapter 18, Problem 12PC
Program Plan Intro

Double Merge

Program Plan:

“NumberList.h”:

  • Include the required specifications into the program.
  • Define a class named “NumberList”.
    • Declare the member variables “value” and “*next” in structure named “ListNode”.
    • Declare the constructor, copy constructor, destructor, and member functions in the class.

“NumberList.cpp”:

  • Include the required header files into the program.
  • Define a function named “appendNode()” to insert the node at end of the list.
    • Declare the structure pointer variables “newNode” and “nodePtr” for the structure named “ListNode”.
    • Assign the value of received variable “num” into “newNode” and assign the “newNode” address into null.
    • Using “if…else” condition check whether the list is empty or not, if the “head” is empty and make a new node into “head” pointer. Otherwise, make a loop find last node in the loop.
    • Assign “newNode” into the variable “nodePtr” value.
  • Define a function named “displayList()” to print the values in the list.
    • Declare the structure pointer “nodePtr” for the structure named “ListNode”.
    • Initialize the variable “dataPtr” with the “head” pointer.
    • Make a loop “while” to display the values of the list.
  • Define a function named “insertNode()” used to insert a value into the list.
    • Declare the structure pointer variables “newNode”, “dataPtr”, and “prev” for the structure named “ListNode”.
    • Make a “newNode” value into the received variable value “num”.
    • Using “if…else” condition to check whether the list is empty or not.
      • If the list is empty, initialize a value into “head” pointer with the value of “newNode” variable.
      • Otherwise, make a “while” loop to test the “num” value is less than the list values.
      • Using “if…else” condition to initialize the value into list.
  • Define a function named “deleteNode()” to delete a value from the list.
    • Declare the structure pointer variables “nodePtr”, and “previousNode” for the structure named “ListNode”.
    • Using “if…else” condition to check the “head” value equal to “num”.
      • Initialize the address of “nodePtr” to the “head”.
      • Remove the value using “delete” operator and reassign the “head” value into the “nodePtr”.
      • If the “num” value not equal to the “head” value, define the “while” loop to assign the “nodePtr” into “previousNode”.
      • Using “if” condition to delete the “previousNode” pointer.
  • Define a destructor named “~NumberList()” to destroy the list values from the memory.
    • Declare the structure pointer variables “nodePtr”, and “nextNode” for the structure named “ListNode”.
    • Initialize the “head” value into the “nodePtr”.
    • Define a “while” loop to make the links of node into “nextNode” and remove the node using “delete” operator.
  • Define a member function named “mergeArray()” to merge the array into list.
    • Using “for” loop to insert a value of the array into list.
    • Make a call to “insertNode()” function to insert an index value of received array “dArray” into list.

“main.cpp”:

  • Include the required header files into the program.
  • Declare a constant variable “n” and initialize a value as “5”.
  • Declare and define a variable “arr” in type of array.
  • Make an object named “obj” for the class “NumberList” and call the member functions “append()” and “display()” using the object.
  • Make a call to “mergeArray()” with arguments of “arr” and “n” and then print the list using “displayList()” function.

Blurred answer
Students have asked these similar questions
whats for dinner? please
Consider the follow program that prints a page number on the left or right side of a page. Define and use a new function, isEven, that returns a Boolean to make the condition in the if statement easier to understand. ef main() :   page = int(input("Enter page number: "))   if page % 2 == 0 :      print(page)   else :      print("%60d" % page)   main()
What is the correct python code for the function def countWords(string) that will return a count of all the words in the string string of workds that are separated by spaces.
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
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning