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++ 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>...
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,...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write()...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write() and read() functions with binary                                                        data, where the data is not char type.              (Typecasting is required) Fill in the blanks, then enter the code and run the program. Note:   The data is int type, so typecasting is            required in the write() and read() functions. #include <iostream> #include <fstream> using namespace std; int main() {    const int SIZE = 10;   ...
11. 4.21 (What Does this Program Do?) What does the following program print? 1 // Exercise...
11. 4.21 (What Does this Program Do?) What does the following program print? 1 // Exercise 4.21: Mystery2.cpp 2 #include <iostream> 3 using namespace std; 4 5 int main() { 6 unsigned int count{1}; 7 8 while (count <= 10) { 9 cout << (count % 2 == 1 ? "****" : "++++++++") << endl; 10 ++count; 11 } 12 }
2. Consider the following program written in C syntax: void swap(int a, int b) {   ...
2. Consider the following program written in C syntax: void swap(int a, int b) {    int temp;    temp = a;    a = b;    b = temp; } void main() {    int value = 2, list[5] = {1, 3, 5, 7, 9};    swap(value, list[0]);    swap(list[0], list[1]);    swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three...
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question....
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question. Thank you! Here’s the contents of a file called example.cpp: // example.cpp #include "LinkedList.h" #include <iostream> #include <string> using namespace std; int main() { cout << "Please enter some words (ctrl-d to stop):\n"; LinkedList lst; int count = 0; string s; while (cin >> s) { count++; lst.add(remove_non_letters(s)); } // while cout << "\n" << count << " total words read in\n"; cout <<...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...