EBK STARTING OUT WITH C++ FROM CONTROL
EBK STARTING OUT WITH C++ FROM CONTROL
9th Edition
ISBN: 8220106714379
Author: GADDIS
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 18.2, Problem 18.6CP

Explanation of Solution

Appending a node:

It is the process of adding a new node at the end of a linked list.

Member function for appending a node:

The following member function is used to append the received value into a list at end:

//Definition of appendNode() function

void IntList::appendNode(int num)

{

//Declare a structure pointer variables

ListNode *newNode, *dataPtr = nullptr;

//Assign a new node

newNode = new ListNode;

//Store the argument value into "newNode"

newNode->value = num;

//Assign the next pointer to be "NULL"

newNode->next = nullptr;

//Condition to check whether the list is empty or not 

if (!head)

//If true, make newNode as the first node

head = newNode;

//else part

else 

{

//Store head value into dataPtr

dataPtr = head;

//Loop to find the last node in the list

while (dataPtr->next)

//Assign last node to the structure variable

dataPtr = dataPtr->next;

//Insert newNode as the last node

dataPtr->next = newNode;

}

}

Explanation:

Consider the function named “appendNode()” to insert the received value “num” at end of the list.

  • Make a new node and assign a received value “num” into the node.
  • Using “if…else” condition check whether the list is empty or not.
    • If the “head” node is empty, assign a new node into “head” pointer.
    • Otherwise, make a loop to find a last node in the list and insert the value at end of the list.

Inserting a node:

It is the process of adding a new node at a specific location in a list.

Member function for inserting a node:

The following member function is used to insert the received value into a list at specific location:

//Definition of insertNode() function

void IntList::insertNode(int num)

{

/*Declare a structure pointer variables*/

ListNode *newNode, *dataPtr, *prev = nullptr;

//Assign a new node

newNode = new ListNode;

//Store the argument value into "newNode"

newNode->value ...

Blurred answer
Students have asked these similar questions
(using R)The iris data set in R gives the measurements in centimeters of the variables sepal length and width andpetal length and width, respectively, for 50 flowers from each of 3 species of iris, setosa, versicolor, andvirginica. Use the iris data set and the t.test function, test if the mean of pepal length of iris flowers isgreater than the mean of sepal length.The iris data set in R gives the measurements in centimeters of the variables sepal length and width andpetal length and width, respectively, for 50 flowers from each of 3 species of iris, setosa, versicolor, andvirginica. Use the iris data set and the t.test function, test if the mean of pepal length of iris flowers isgreater than the mean of sepal length.
Recognizing the Use of Steganography in Forensic Evidence (4e)Digital Forensics, Investigation, and Response, Fourth Edition - Lab 02
Write a Java Program to manage student information of a university. The Javaprogram does the following steps:a) The program must use single-dimensional arrays to store the studentinformation such as Student ID, Name and Major.b) The program asks the user to provide the number of students.c) The program asks the user to enter the Student IDs for the number of studentsand stores them.d) The program asks the user to enter the corresponding names for the numberof students and stores them.e) The program then asks the user to provide the corresponding major for thestudents and stores them.f) The program then should display the following options:1. ID Search2. Major Enrollment3. Exitg) On selecting option 1, the user can search for a student using Student ID. Theprogram asks the user to enter a Student ID. It then should print thecorresponding student’s details such as Name and Major if the user providedStudent ID number is present in the stored data. If the user’s Student IDnumber does not…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,