MyProgrammingLab - For Gaddis: Starting Out with C++ From Control Structures through Objects
MyProgrammingLab - For Gaddis: Starting Out with C++ From Control Structures through Objects
15th Edition
ISBN: 9780133780611
Author: Pearson
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 17, Problem 33RQE
Program Plan Intro

Purpose of the given code:

The given code is trying to insert the value of the variable “num” into the end of a linked list.

Given Code:

//Definition of function

void NumberList::appendNode(double num)//Line 1

{//Line 2

//Declaration of structure pointer variable

ListNode *newNode, *nodePtr;//Line 3

//Allocate a new node & store num

//Error #1

newNode = new listNode;//Line 4

newNode->value = num;//Line 5

// If there are no nodes in the list

// make newNode the first node

if (!head)//Line 6

head = newNode;//Line 7

// Otherwise, insert newNode at end

else //Line 8

{//Line 9

//Error #2

// Find the last node in the list

while (nodePtr->next)//Line 10

nodePtr = nodePtr->next;//Line 11

// Insert newNode as the last node

nodePtr->next = newNode;//Line 12

}//Line 13

}//Line 14

Blurred answer
Students have asked these similar questions
Duplicate Set This function will receive a list of elements with duplicate elements. It should add all of the duplicate elements to a set and return the set containing the duplicate elements. A duplicate element is an element found more than one time in the specified list. The order of the set does not matter. Signature: public static HashSet<Object> duplicateSet(ArrayList<Object> list) Example: INPUT: [2, 4, 5, 3, 3, 5] OUTPUT: {5, 3}
You are required to complete the LinkedList class. This class is used as a linked list that has many methods to perform operations on the linked list. To create a linked list, create an object of this class and use the addFirst or addLast or add(must be completed) to add nodes to this linked list. Your job is to complete the empty methods. For every method you have to complete, you are provided with a header, Do not modify those headers(method name, return type or parameters). You have to complete the body of the method. package chapter02;

public class LinkedList
{
   protected LLNode list;

   public LinkedList()
   {
      list = null;
   }

   public void addFirst(T info)
   {
      LLNode node = new LLNode(info);
      node.setLink(list);
      list = node;
   }

   public void addLast(T info)
   {
      LLNode curr = list;

      LLNode newNode = new LLNode(info);
      if(curr == null)
      {
         list = newNode;
      }
      else
      {
         while(curr.getLink() !=…
1.Assume some Node class with info link fields . Complete this method in class List that returns a reference to the node containing the data item in the argument findThis, Assume that findThis is in the list    public class list  { protected Node head ; Protected int size ; Public Node find (char find this)     {     Node curr = head;        while(curr != null)       {         if(curr.info == findThis)             return curr;         curr = curr.link;       }         return -1;                               } }
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