Question

Must be written in c++: This problem solely involves your demonstration of the proper usage of...

Must be written in c++:


This problem solely involves your demonstration of the proper usage of C++ STL std::list<int>

Below you will be given four total functions to develop (two are listed here, two separately after)

  • Put all four of your functions in the same single source code file
  • Submit ONLY your one source code CPP file online
  • Submitting two or three or more separate CPP files will lose points

(1) The first function you will need to implement is the main() function of course

  • int main()
  • Add proper testing in the main() function to prove your other functions work as intended
  • One or two tests of each function is all that is needed

(2) The second function you will need to implement is one which prints all elements of a list collection

  • void PrintAllElementsOfList(const std::list<int> & list)
  • Put a space between each list element
  • This will be great for ensuring your functions do what they are meant to do!

You are free to create your own test data as you see fit, however these linked lists of integers represent test cases for all possible functions to develop:

  • a = { 1, 3, 5, 7, 9, 11, 13, 15 }
  • b = { 2, 4, 6, 8, 10, 12, 14, 16 }
  • c = { 1, 2, 2, 3, 4, 4, 5, 6, 6 }
  • d = { 1, 4, 5, 8, 9 }
  • e = { 9, 5, 4, 3, 3, 4, 5, 9 }
  • f = { 1, 1, 2, 2, 3, 3, 4, 4 }
  • g = { 1, 2, 3, 4, 5 }

Homework Answers

Answer #1

// C++ Code:-

#include<bits/stdc++.h>
using namespace std;

// Function to prints all elements of a list collection with space seperated.
void PrintAllElementsOfList(const std::list<int> & list)
{
for(auto it=list.begin(); it!=list.end();++it)
cout<<*it<<" ";
cout<<endl;
}

// main function to check the implementation of all other function
int main()
{
// Declaring some list given in question
list<int> a{ 1, 3, 5, 7, 9, 11, 13, 15 };
list<int> b{ 2, 4, 6, 8, 10, 12, 14, 16 };
list<int> c{ 1, 2, 2, 3, 4, 4, 5, 6, 6 };
list<int> d{ 1, 4, 5, 8, 9 };
list<int> e{ 9, 5, 4, 3, 3, 4, 5, 9 };
list<int> f{ 1, 1, 2, 2, 3, 3, 4, 4 };
list<int> g{ 1, 2, 3, 4, 5 };
  
// Printing the elements of all list by calling PrintAllElementsOfList function
// One by one
  

cout<<"List 1: ";
PrintAllElementsOfList(a);
  
cout<<"List 2: ";
PrintAllElementsOfList(b);
  
cout<<"List 3: ";
PrintAllElementsOfList(c);
  
cout<<"List 4: ";
PrintAllElementsOfList(d);
  
cout<<"List 5: ";
PrintAllElementsOfList(e);
  
cout<<"List 6: ";
PrintAllElementsOfList(f);
  
cout<<"List 7: ";
PrintAllElementsOfList(g);
return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Implement functions for insertion sort, quicksort, heapsort and merge sort that input an array of integers...
Implement functions for insertion sort, quicksort, heapsort and merge sort that input an array of integers and sort it in-place. Write a program that generates random integer arrays (hint: use seed appropriately to avoid generating same sequences) of lengths 10, 100, 1000, 10,000, 100,000, 1000,000, and then sorts each using each of the sorting functions from (a), and measures the time in nanoseconds. The program will repeat this process 30 times and will compute the average execution time for each...
*****C++ program***** Please implement the following, comments throughout code to explain, and provide screenshots of output...
*****C++ program***** Please implement the following, comments throughout code to explain, and provide screenshots of output for proof. Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Implement the following functions: Implement a function called readData int readData( int *arr) arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers from a file call data.txt into the array arr....
In this problem, you will write an implementation of BubbleSort. Your function should take in a...
In this problem, you will write an implementation of BubbleSort. Your function should take in a single line representing an array of integers, and output a single line containing the list in ascending order. For example, if you receive the following input followed by a newline: 8 7 6 5 4 3 2 1 then you should display the following output followed by a newline: 1 2 3 4 5 6 7 8 Starter code for reading the input and...
***C++ CODING*** Write a program for sorting a list of integers in ascending order using the...
***C++ CODING*** Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Requirements Implement the following functions: Implement a function called readData int *readData( )   The function returns a pointer that points to the locations with integers reading from the file data.txt. arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers from a file call data.txt into the array...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment 2 (karatsuba.cpp) in Canvas (please do not rename file or use cout/cin statements in your solution). As a reminder, the algorithm uses recursion to produce the results, so make sure you implement it as a recursive function. Please develop your code in small The test program (karatsuba_test.cpp) is also given. PLEASE DO NOT MODIFY THE TEST FILE. KARATSUBA.CPP /* Karatsuba multiplication */ #include <iostream>...
I have written working code for this problem however it is not producing an output and...
I have written working code for this problem however it is not producing an output and it states is a wrong answer. Please just fix my code below and make it work for the sample test cases and all test cases. You are given a pointer to the root of a binary search tree and values to be inserted into the tree. Insert the values into their appropriate position in the binary search tree and return the root of the...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class and a Node class (please name your classes exactly ​as I did here). Please follow the below specifications for the two classes. Node.cpp ● This must be a generic class. ● Should contain a generic member variable that holds the nodes value. ● Should contain a next and prev Node* as denoted here. ● All member variables should be private. ● Use public and...
Project 1 - NodeList write in c++ with 5 files: main.cpp List.h List.cpp ListNode.h ListNode.cpp Building...
Project 1 - NodeList write in c++ with 5 files: main.cpp List.h List.cpp ListNode.h ListNode.cpp Building upon the the ListNode/List code I would like you to extend the interface of a list to have these member functions as well. struct ListNode { int element; ListNode *next; } Write a function to concatenate two linked lists. Given lists l1 = (2, 3, 1)and l2 = (4, 5), after return from l1.concatenate(l2)the list l1should be changed to be l1 = (2, 3,...
Be sure to create the algorithms (pseudocode or flowcharts) for all 4 functions plus the main...
Be sure to create the algorithms (pseudocode or flowcharts) for all 4 functions plus the main program. Create a very simple larger( ) function that takes 2 positive numbers as parameters and returns the larger value of the two numbers.    Use your larger function to help create the following functions -- reuse your function code. Create a simple larger3( ) function that takes 3 positive numbers as parameters and returns the largest value of the three numbers.   Create a simple...
Please follow ALL the instructions and solve it by C++. Please and thank you! There are...
Please follow ALL the instructions and solve it by C++. Please and thank you! There are two ways to write loops: (1) iterative, like the for-loops we're used to using, and (2) recursive. Your prerequisite preparation for this course should have exposed you to both, although your working knowledge of recursive loops may not be as strong as that of iterative loops. Consider the following iterative function that prints an array of characters backward: #include <iostream> #include <cstring> // print...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT