CSE 112 - Introduction to Computer Science II CSE 112 - Lab # 10 Linked List...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
CSE 112 - Introduction to Computer Science II CSE 112 - Lab # 10 Linked List using the STL list container - Linked Lists Requirements: Using the STL list container, create the list on page 1157 (18-6), and modify the program as described below. ● Define a list object, and populate it using a loop as shown in 18-6. ● Call a function to display the list and output the number of nodes in the list. ● Then, call a function to add to the list the numbers (5, 15, 25, 35, 45, 55, 65, 75, 85) inserting them in numerical order using a loop, an iterator, list.begin, and list.insert. ● Then call the display function to display the list again and the number of nodes. Then reverse the list and display it again, and output the number of nodes. ● Then call a function that removes the ends of the list, and then redisplay the list and the number of nodes. . Use an iterator in the solution for adding the fives and for output at a minimum. All output is to be done in the output function. The output function that displays the list must accept a string for the message prior to displaying the list and the number of nodes. Sample output function declaration: void display_list(list<int> &myList, string message); display_list(myList, "The original list is: "); Sample output function call: Output Format and contents: The original list is: 0 10 20 30 40 50 60 70 80 90 The number of list nodes is: 10 The list with the additional numbers is: 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 The number of list nodes is now: 19 The list in reverse is: 90 85 80 75 70 65 60 55 50 45 40 35 30 25 20 15 10 5 0 The number of list nodes is: 19 The list with the ends removed: 85 80 75 70 65 60 55 50 45 40 35 30 25 20 15 10 5 The number of list nodes is: 17 Process returned 0 (0x0) execution time: 0.062 s Press any key to continue. Grading will be based on meeting all of the lab requirements, adherence to programming standards, operation and accurate output, and programming style including white space and indentation. The grade penalty is 5% for each standards violation or missing requirement. Program 18-6 demonstrates some simple operations with the 11st container. Program 18-6 1 // This program demonstrates the STL list container. 2 #include <iostream> 3 #include <list> 4 using namespace std; 5 6 int main() 7 ( 8 // Define an empty list. 9 list<int> myList; 11 Add some values to the list. for (int x = 0; x< 100; x + 10) nyList.push_back (x): // Use an iterator to display the values. for (auto it cout << it << **; cout << endl; 10 11 12 13 14 15 16 17 18 19 1158 Chapter 18 Linked Lists C a myList.begin(): it ! myList.end(); it++) Program 18-6 (continued) 2222 (program continues) 1/ Now reverse the order of the elements. myList.reverse(); // Display the values again, with a range-based for loop myList) cout << element << " "; The forward_list Container Because a forward list is implemented as a singly linked list, cach node keeps only one pointer: a pointer to the next node. Compared to a list container, which keeps two point- ers per node (one to the next node, and one to the previous node), a forward_list uses less memory than a list. However, you can step only forward through a forward_list. If you need to move both forward and backward, you will need to use a list container. The forward list container provides most of the same member functions as the 11st con- tainer, with a few exceptions. You can find documentation for the forward_list container with a good online reference site, such as www.cppreference.com or www.cplusplus.com. 24 for (auto element 25 26 cout << endl; 27 28 return 0; 29 ) Program Output 0 10 20 30 40 50 60 70 80 90 90 80 70 60 50 40 30 20 10 0 C CSE 112 - Introduction to Computer Science II CSE 112 - Lab # 10 Linked List using the STL list container - Linked Lists Requirements: Using the STL list container, create the list on page 1157 (18-6), and modify the program as described below. ● Define a list object, and populate it using a loop as shown in 18-6. ● Call a function to display the list and output the number of nodes in the list. ● Then, call a function to add to the list the numbers (5, 15, 25, 35, 45, 55, 65, 75, 85) inserting them in numerical order using a loop, an iterator, list.begin, and list.insert. ● Then call the display function to display the list again and the number of nodes. Then reverse the list and display it again, and output the number of nodes. ● Then call a function that removes the ends of the list, and then redisplay the list and the number of nodes. . Use an iterator in the solution for adding the fives and for output at a minimum. All output is to be done in the output function. The output function that displays the list must accept a string for the message prior to displaying the list and the number of nodes. Sample output function declaration: void display_list(list<int> &myList, string message); display_list(myList, "The original list is: "); Sample output function call: Output Format and contents: The original list is: 0 10 20 30 40 50 60 70 80 90 The number of list nodes is: 10 The list with the additional numbers is: 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 The number of list nodes is now: 19 The list in reverse is: 90 85 80 75 70 65 60 55 50 45 40 35 30 25 20 15 10 5 0 The number of list nodes is: 19 The list with the ends removed: 85 80 75 70 65 60 55 50 45 40 35 30 25 20 15 10 5 The number of list nodes is: 17 Process returned 0 (0x0) execution time: 0.062 s Press any key to continue. Grading will be based on meeting all of the lab requirements, adherence to programming standards, operation and accurate output, and programming style including white space and indentation. The grade penalty is 5% for each standards violation or missing requirement. Program 18-6 demonstrates some simple operations with the 11st container. Program 18-6 1 // This program demonstrates the STL list container. 2 #include <iostream> 3 #include <list> 4 using namespace std; 5 6 int main() 7 ( 8 // Define an empty list. 9 list<int> myList; 11 Add some values to the list. for (int x = 0; x< 100; x + 10) nyList.push_back (x): // Use an iterator to display the values. for (auto it cout << it << **; cout << endl; 10 11 12 13 14 15 16 17 18 19 1158 Chapter 18 Linked Lists C a myList.begin(): it ! myList.end(); it++) Program 18-6 (continued) 2222 (program continues) 1/ Now reverse the order of the elements. myList.reverse(); // Display the values again, with a range-based for loop myList) cout << element << " "; The forward_list Container Because a forward list is implemented as a singly linked list, cach node keeps only one pointer: a pointer to the next node. Compared to a list container, which keeps two point- ers per node (one to the next node, and one to the previous node), a forward_list uses less memory than a list. However, you can step only forward through a forward_list. If you need to move both forward and backward, you will need to use a list container. The forward list container provides most of the same member functions as the 11st con- tainer, with a few exceptions. You can find documentation for the forward_list container with a good online reference site, such as www.cppreference.com or www.cplusplus.com. 24 for (auto element 25 26 cout << endl; 27 28 return 0; 29 ) Program Output 0 10 20 30 40 50 60 70 80 90 90 80 70 60 50 40 30 20 10 0 C
Expert Answer:
Related Book For
The Architecture of Computer Hardware, Systems Software and Networking An Information Technology App
ISBN: 978-1118322635
5th edition
Authors: Irv Englander
Posted Date:
Students also viewed these accounting questions
-
A program for generating random numbers on a computer is to be tested. The program is instructed to generate 100 single-digit integers between 0 and 9. The frequencies of the observed integers are as...
-
A rectangular container measuring 25 cm x 35cm x 55 cm is filled with water. What is the mass of this volume of water?
-
A computer lab at a small college has 25 computers. Twice during the day, a full scan for viruses is performed on each computer. Because of differences in the configuration of the computers, the...
-
A bank reconciliation takes time and must balance. An employee was struggling in balancing the bank reconciliation. Her supervisor told her to plug (make an unsupported entry for) the difference,...
-
Tim Raven is an independent fraud investigator called to investigate an anonymous tip made on the tip line of the Wilson Fast automobile dealership. The tip reads as follows: I am an employee of the...
-
What are some well thought out questions to ask a client when creating a web site ?
-
For each of the following, (a) calculate the mean, standard deviation, and standard error of the mean for each Group and (b) construct a bar graph (assume the independent variable is condition and...
-
Summer Fun manufactures flotation vests in Tampa, Florida. Summer Funs contribution margin income statement for the month ended December 31, 2016, contains the following data: Suppose Over-town...
-
Let f(x) In(x). Solve each of the following equations exactly for a. (f(x)) = 11 b. f(x) = 11 c. f(x) = 11
-
In the figure for Problem 13-35, pinion 2 is to be a right-hand helical gear having a helix angle of 30, a normal pressure angle of 20, 16 teeth, and a normal diametral pitch of 6 teeth/in. A motor...
-
Your boss has just asked you to calculate your firm's cost of capital. Below is potentially relevant information for your calculation. What is your firm's Weighted Average Cost of Capital? Common...
-
How should expenses such as repairs be addressed in a property manager's operating budget? a. Allocation of a cash reserve fund b. Establishment of funds for capital expenditures c. Money set aside...
-
A regulatory specialist may be tasked with presenting regulatory information on provider and patient rights in a way that all department employees and patients will understand the importance of...
-
ASSESSMENT 2 - PROJECT STUDENT INFORMATION This information is to be handed to each student to outline the assessment requirements PART - A For this assessment, you are required to administer...
-
Workbook activity chapter 10,lesson 4. The document is on Google as well Image transcription text :05 2000896:077 2. 752 24 10 28 Account number Drawe ns Write a check to each of these persons. Use...
-
If a company purchased equipment then its choices total assets will stay the same. total assets will decrease. total assets will increase.
-
Managing the flow of goods both within and outside the firm from point of origin to point of consumption is known as: a. Value Chains b. Operations Management c. Procurement Science d. Supply Chain...
-
Use of the contraceptive Depo Provera appears to triple women's risk of infection with chlamydia and gonorrhea , a study reports today. An estimated 20 million to 30 million women worldwide use Depo...
-
The book compares a large mainframe computer to a smartphone or tablet, and states that the difference between them is one of magnitude, not of concept. Explain the meaning of that statement.
-
Exponents are normally stored in excess-N notation. Explain excess-N notation. If a number is stored in excess-31 notation and the actual exponent is 2 +12 , what value is stored in the computer for...
-
Using the powers of each digit in base 8, convert the decimal number 6026 to octal.
-
Describe the five financial statements and how they are prepared.
-
Presented below in alphabetical order are statement of financial position items for Feagler Gardening at December 31, 2025. Prepare a statement of financial position following the format of...
-
Presented below is selected information related to Tsui Repairs at December 31, 2025. Tsui reports financial information monthly (amounts in thousands). a. Determine the total assets of Tsui Repairs...
Study smarter with the SolutionInn App