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,...
-
Can a firm operating in the upward- sloping portion of its average cost curve be a natural monopoly? Explain.
-
The following data was compiled from the financial records for the month of May Standard Actual, Direct Materials Price $7.25 $7.46 Direct Materials Quantity 8,000 7,895 Direct Labor Rate $38.00...
-
How and why does an auditor test earnings per share?
-
The Pro Apparel Company manufactures baseball-style caps with various team logos. The caps come in an assortment of designs and colors. The company has had monthly sales for the past 24 months as...
-
Karen earns a salary of $30,000 per year. For the pay period of April 26 to May 9th, how much of Karen's salary expense would be accrued on the April 30 financial statements of the hotel she works...
-
Tuckered Outfitters plans to market a custom brand of packaged trail mix. The ingredients for the trail mix will include Raisins, Grain, Chocolate Chips, Peanuts, and Almonds costing, respectively,...
-
Mr. Johnson has 2 medical insurance policies. To prevent duplication of payment for the same medical expense, the policies include a Question 7 options: coordination of benefits statement....
-
Does increasing redundancy increase or decrease reliability?
-
Does increasing system complexity without increasing redundancy then increase or decrease system reliability?
-
What are some of the key criteria for choosing a valuation method?
-
Describe the process of estimating the appropriate risk-free rate for estimating a DCF discount rate. Where can data be found for estimating the risk-free rate?
-
A manager assumes an unlikely request in an order must be the result of some unusual customer. Is this an example of outcome bias or normalization?
-
What happens to the pressure of a sample of gas if it is allowed to exp three times its original volume? The temperature remains constant. Pressure is reduced by a third Pressure is halved Pressure...
-
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.
-
Using the information presented in Figure 1.1, list THREE key user groups for each of the following organizations and briefly explain what each group might hope to ascertain from the publicly...
-
Can you provide a suggestion for each of the following, briefly explaining your rationale: (i) A balance which could be material owing to its magnitude? (ii) A balance which could be material owing...
-
The internationalization of financial reporting has attracted significant attention. There are many in favour and, equally, many opposed. The United States (US), for example, has continued to use US...
Study smarter with the SolutionInn App