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 18, Problem 1PC
Program Plan Intro

Linked List Operations

Program Plan:

“IntList.h”:

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

“IntList.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 “dataPtr” for the structure named “ListNode”.
    • Assign the value “num” to the variable “newNode” and assign null to the variable “newNode”.
    • Using “if…else” condition check whether the list is empty or not, if the “head” is empty then make a new node into “head” pointer. Otherwise, make a loop to find last node in the loop.
    • Assign the value of “dataPtr” into the variable “newNode”.
  • Define a function named “display()” to print the values in the list.
    • Declare the structure pointer “dataPtr” 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()” 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”.
    • Use “if…else” condition to check whether the list is empty or not.
      • If the list is empty then initialize “head” pointer with the value of “newNode” variable.
      • Otherwise, make a “while” loop to test whether the “num” value is less than the list values or not.
      • Use “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 “dataPtr”, and “prev” for the structure named “ListNode”.
    • Use “if…else” condition to check whether the “head” value is equal to “num” or not.
      • Initialize the variable “dataPtr” with the value of the variable “head”.
      • Remove the value using “delete” operator and reassign the “head” value into the “dataPtr”.
      • If the “num” value not equal to the “head” value, then define the “while” loop to assign the “dataPtr” into “prev”.
      • Use “if” condition to delete the “prev” pointer.
  • Define the destructor to destroy the list values from the memory.
    • Declare the structure pointer variables “dataPtr”, and “nextNode” for the structure named “ListNode”.
    • Initialize the variable “dataPtr” with the “head” pointer.
    • Define a “while” loop to make the links of node into “nextNode” and remove the node using “delete” operator.

“Main.cpp”:

  • Include the required header files into the program.
  • Declare an object named “obj” for the class “IntList”.
  • Make a call to functions for insert, append, and delete operations.

Blurred answer
Students have asked these similar questions
A business that sells dog food keeps information about its dog food products in a linked list.  The list is named dogFoodList.  (This means dogFoodList points to the first node in the list.)  A node in the list contains the name of the dog food (a String), a dog food ID (also a String)  and the price (a double.) a.)  Create a class for a node in the list. b.)   Use this class to write pseudocode or Java for a public method that prints the name of all dog foods in the list where the price is more than $20.00.
C# Assume you have a LinkedList of Node objects.  Both classes have all the normal operations shown below.  Your job is to program the DeleteTail method of the LinkedList class.  This method locates and deletes the last element of the linked list.  You may not change its signature line. Keep your code clean, but no documentation is necessary. A good solution will be between 5 and 10 lines of code, not counting whitespace.
Linked List, create your own code. (Do not use the build in function or classes of Java or from the textbook). Create a LinkedList class: Call the class MyLinkedList, (hint) Create a second class called Node.java and use it, remember in the class I put the Node class inside the LinkedList Class, but you should do it outside. This class should haveo Variables you may need for a Node,o (optional) Constructor Your linked list is of an int type. (you may do it as General type as <E>) For this Linked List you need to have the following methods: add, addAfter, remove, size, contain, toString, compare, addInOrder. This is just a suggestion, if you use Generic type, you must modify this Write a main function or Main class to test all the methods,o Create a 2 linked list and test all your methods. (Including the compare)
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education