STARTING OUT WITH C++ MPL
STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
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
6. Suppose that we have defined a singly linked list class that contains a list of unique integers in ascending order. Create a method that merges the integers into a new list. Note the additional requirements listed below. Notes: ● . Neither this list nor other list should change. The input lists will contain id's in sorted order. However, they may contain duplicate values. For example, other list might contain id's . You should not create duplicate id's in the list. Important: this list may contain duplicate id's, and other list may also contain duplicate id's. You must ensure that the resulting list does not contain duplicates, even if the input lists do contain duplicates.
C++ Programming Language ::::::: Redo the same functions this time as nonmember functions please : NOTE: You can add only one function into the linked list class get_at_position which will return value of element at given position. 1) Insert before tail :  Insert a value into a simply linked list, such that it's location will be before tail. So if a list contains {1, 2, 3}, insert before tail value 9 is called, the list will become {1, 2, 9, 3}. 2) Insert before value :  Insert a value into a simply linked list, such that it's location will be before a particular value. So if a list contains {1, 2, 3}, insert before 2 value 9 is called, the list will become {1, 9, 2, 3}. 3)Count common elements : Count common values between two simply linked lists.So if a list1 contains {1, 2, 3, 4, 5}, and list2 contains {1, 3, 4, 6}, number of common elements is 3. 4) Check if sorted : Check if elements of simply linked lists are sorted in ascending order or not.So if a list contains {1, 3, 7, 8, 9}…
The definition of linked list is given as follows: struct Node {    ElementType Element ;    struct Node *Next ; } ; typedef struct Node  *PtrToNode, *List, *Position; If L is head pointer of a linked list, then the data type of L should be ??
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