Starting out With C++, Early Objects - Access
Starting out With C++, Early Objects - Access
8th Edition
ISBN: 9780133452259
Author: GADDIS
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 17, Problem 1PC
Program Plan Intro

Simple Linked List Class

Program Plan:

  • Include the required specifications into the program.
  • Declare a class ListNode.
    • Declare the member variables “value” and “*p” in structure named “ListNode”.
    • The data value of node is stored in variable v and address to next pointer is stored in pointer p
    • Declare the constructor, destructor, and member functions in the class.
    • Declare the structure variable “next” and a friend class Linked List
  • Declare a class LinkList.
    • Function to insert elements into the linked list “void add(double n)” is defined.
    • Function to check whether a particular node with a data value n is a part of linked list or not “bool isMember(double n)”.
    • Declaration of structure variable head to store the first node of the list “ListNode * head” is defined.
    • A function “void LinkedList::add(double n)” is defined which adds or inserts new nodes into the link list.
    • A function “bool LinkedList::isMember(double n)” is defined which  searches for a given data value within the nodes present in the link list.
    • A destructor “LinkedList::~LinkedList()” deallocates the memory for the link list.
  • Declare the main class.
    • Create an empty list to enter the data values into the list.
    • Input “5” numbers from user and insert the data values into the link list calling “void LinkedList::add(double n)” function.
    • Check whether a data value is a member of the linked list or not by calling the “bool LinkedList::isMember(double n)” function.
    • Print whether the data value entered is present within the link list or not.

Blurred answer
Students have asked these similar questions
In this chapter, the class to implement the nodes of a linked list is defined as a struct. The following rewrites the definition of the struct nodeType so that it is declared as a class and the member variables are private. template <class Type>class nodeType{public:const nodeType<Type>& operator=(const nodeType<Type>&);//Overload the assignment operator.void setInfo(const Type& elem);//Function to set the info of the node.//Postcondition: info = elem;Type getInfo() const;//Function to return the info of the node.//Postcondition: The value of info is returned.void setLink(nodeType<Type> *ptr);//Function to set the link of the node.//Postcondition: link = ptr;nodeType<Type>* getLink() const;//Function to return the link of the node.//Postcondition: The value of link is returned.nodeType();//Default constructor//Postcondition: link = NULL;nodeType(const Type& elem, nodeType<Type> *ptr);//Constructor with parameters//Sets info point to…
In this chapter, the class to implement the nodes of a linked list is defined as a struct . The following rewrites the definition of the struct nodeType so that it is declared as a class and the member variables are private. template <class Type> class nodeType{ public:     const nodeType<Type>& operator=(const nodeType<Type>&);        //Overload the assignment operator.     void setInfo(const Type& elem);      //Function to set the info of the node.      //Postcondition: info = elem;     Type getInfo() const;      //Function to return the info of the node.      //Postcondition: The value of info is returned.     void setLink(nodeType<Type> *ptr);      //Function to set the link of the node.      //Postcondition: link = ptr;     nodeType<Type>* getLink() const;      //Function to return the link of the node.      //Postcondition: The value of link is returned.     nodeType();       //Default constructor       //Postcondition: link = nullptr;…
(IntelliJ) Write an easier version of a linked list with only a couple of the normal linked list functions and the ability to generate and utilize a list of ints.  The data type of the connection to the following node can be just Node, and the data element can be just an int. You will need a reference (Java) or either a reference or a pointer (C++) to the first node, as well as one to the last node. * Create a method or function that accepts an integer, constructs a node with that integer as its data value, and then includes the node to the end of the list.  If the new node is the first one, this function will also need to update the reference to the first node. This function will need to update the reference to the final node.  Consider how to insert the new node following the previous last node, and keep in mind that the next reference for the list's last node should be null. * Create a different method or function that iteratively explores the list, printing the int data values as…
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