C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 19, Problem 19.8E
Program Plan Intro
- Include required header files
- Create class list. Define structure , create its members intdata and node *next. Declare pointer to structure *start
- Define one constructor
- Define member functions input, display, addNode and addition
- Create a main function
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Summing and Averaging Elements in a List) Write a program that inserts 25 random integers from 0 to 100 in order in a linked list object. The program should calculate the sum of the elements and the floating-point average of the elements.
Topic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. (See attached photo for reference)
int removeAt(int pos)
Removes the number in the posth position of the list and returns the element removed.
Performing removeAt(3) in the example list will remove the 3rd element of the linked list and the updated list will be: 10 -> 30 -> 50
When the value of pos is greater than the size or less than one, return -1.
int removeAll(int num)
Removes all instances of num in the linked list and returns the number of instances removed.
In this list 10 -> 10 -> 20 -> 30 -> 10, performing removeAll(10) will remove all three 10's and the list will look like this: 20 -> 30. Then, it will return the number of instances removed, in this case, 3.
int contains(int num)
This will return the position of the first instance of the element num in the list. If num is not found, return 0. In the example, having the method contains(30) will…
4
Chapter 19 Solutions
C++ How to Program (10th Edition)
Ch. 19 - Prob. 19.6ECh. 19 - Prob. 19.7ECh. 19 - Prob. 19.8ECh. 19 - Prob. 19.9ECh. 19 - Prob. 19.10ECh. 19 - Prob. 19.11ECh. 19 - (Infix-to-Post fix conversion) Stacks are used by...Ch. 19 - Prob. 19.13ECh. 19 - Prob. 19.14ECh. 19 - Prob. 19.15E
Ch. 19 - Prob. 19.16ECh. 19 - Prob. 19.17ECh. 19 - (Duplicate Elimination) In this chapter, we saw...Ch. 19 - Prob. 19.19ECh. 19 - Prob. 19.20ECh. 19 - Prob. 19.21ECh. 19 - Prob. 19.22ECh. 19 - Prob. 19.23ECh. 19 - Prob. 19.24ECh. 19 - Prob. 19.25ECh. 19 - Prob. 19.26ECh. 19 - Prob. 19.27ECh. 19 - Prob. 19.28E
Knowledge Booster
Similar questions
- ( JAVA LANGUAGE ) Create and print a linked list with four (4) elements. Ice cream flavors will be the basis of the required values for the linked listarrow_forwardTopic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. Below are the "CODE THAT NEEDS TO BE IMPROVED" or "NOT FINAL CODE" (See attached photo for reference) int add(int num) This will add the element num into the linked list and return the position of the newly-added element. In the above example, having add(60) will return 5 as it is the fifth position in the list. int remove(int num) This will remove the first instance of the element and return the position of the removed element. In the above example, having remove(40) will return 3 as 40 was the third element in the linked list before having removed. int get(int pos) This method will get the element at the specified position. This will return -1 if the specified position is invalid. int add(int num) { addTail(num); return index; } int remove(int num) { node* currnode = head; node* prevnode = NULL;…arrow_forward- Question-2: Functions, Iterations and List • Write a function that takes a positive integer n as its parameter. • Return a list whose o values are numbers between n and 2n.arrow_forward
- Use c++ Write a program that uses the STL list container to create a linked list of integers. The program will ask the user to provide a list of integers. When the user is finished, the program will list the integers entered by the user and show the average of those integers. Additionally, you need to add the following code: Display your name (first and last) before you ask the user to enter the integers. You need to do one of the followings: (do not do all three) if the first letter of your last name is between and including A through G, compute the maximum value entered by the userarrow_forwardC++ PROGRAMMING (Linked list) complete the functions: You have to continue on implementing your Array List namely the following functions: Example ArrayList: [10, 30, 40, 50] void addAt(int num, int pos) This method will add the integer num to the posth position of the list. Performing addAt(20, 2) in the example list will add 20 at the 2nd position and the array will now look like this: [10, 20, 30, 40, 50] When the value of pos is greater than the size + 1 or less than one, output "Position value invalid" void removeAt(int pos) Removes the number in the posth position of the list. Performing removeAt(3) in the example list will remove the 3rd element of the list and the updated array will be: [10, 30, 50] When the value of pos is greater than the size or less than one, output "Position value invalid" My incomplete code: #include <cstdlib>#include <iostream>using namespace std; class ArrayList : public List { // : means "is-a" / extend int* array; int index;…arrow_forwardTOPIC: Singly Linked ListImplement the following functions using C++ int add(int num) This will add the element num into the linked list and return the position of the newly-added element. In the above example, having add(60) will return 5 as it is the fifth position in the list. int remove(int num) This will remove the first instance of the element and return the position of the removed element. In the above example, having remove(40) will return 3 as 40 was the third element in the linked list before having removed. int get(int pos) This method will get the element at the specified position. This will return -1 if the specified position is invalid. bool addAt(int num, int pos) This method will add the integer num to the posth position of the list and returns true if the value of pos is valid. Performing addAt(20, 2) in the example list will add 20 at the 2nd position and the linked list will now look like this: 10 -> 20 -> 30 -> 40 -> 50. When the value of pos is…arrow_forward
- Which of the following statements are correct (assuming O notation)? 1.Deleting an element is slower for a linked list than for an array 2.Random access of elements in an array is O(1) 3.Linked lists are more memory-efficient than arraysarrow_forwardwrite a c++ program which 1)store the 10 names of your friends in array lists(duplicate no allowed) 2)print all elements of list using loop 3)remove a particular name from list 4)print all elementsarrow_forward.arrow_forward
- Identify the difference between STACK and ARRAY.arrow_forwardTopic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. Below is the "CODE THAT NEEDS TO BE IMPROVED" or "NOT FINAL CODE" (See attached photo for reference) bool addAt(int num, int pos) This method will add the integer num to the posth position of the list and returns true if the value of pos is valid. Performing addAt(20, 2) in the example list will add 20 at the 2nd position and the linked list will now look like this: 10 -> 20 -> 30 -> 40 -> 50. When the value of pos is invalid i.e. greater than the size + 1 or less than one, return false. bool addAt(int num, int pos) { if (pos == 1) { // case 1: addHead addHead(num); return true; } if (pos == index + 1) { // case 3: addTail addTail(num); return true; } node* currnode = head; //addAt(20, 3) int count = 0; while (currnode…arrow_forwardPlease code using C++ and only use the headers <iostream>. The use of any other headers will not be accepted. Thank you!arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education