Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Find Duplicates Write a function called find_dups that takes a list of int's as a parameter and returns a list of values that are duplicated

Find Duplicates

Write a function called find_dups that takes a list of int's as a parameter and returns a list of values that are duplicated in the given list. For example, if the given list contains values { 10, 20, 10, 30, 40, 20, 10 }, the list returned by your function should contain values { 10, 20 }. The order of the values in the returned list is not important, but the returned list should not contain any duplicates (i.e. the example had three 10's, but 10 shows up only once in the returned list). You will need to devise an algorithm for finding the duplicates. Suggestions will be given in class. You are free to use any member functions of the list class or functions included in the algorithm library. Once you have completed the function and tested it, determine the run-time (Big Oh) of your function. Remember to consider the run times of any library functions used as part of the solution. Explain how you arrived at the run-time, and note any assumptions you may have made regarding the run-times of any library functions.

Give your analysis of your function in file README.md.

#include #include using namespace std;

list find_dups (const list& thelist); void print_list (const list& thelist);

int main() { // A few lists for testing list list1 = { 4, 7, 1, 4, 3, 8, 9, 2 }; list list2 = { 11, 31, 22, 22, 41, 56, 55, 31, 41, 31 }; list list3 = { 4, 6, 2, 1, 3, 8, 5, 3, 1, 5, 9, 3, 4, 9, 7, 3 };

cout << "Duplicates in list1:"; print_list(find_dups(list1)); cout << "Duplicates in list2:"; print_list(find_dups(list2)); cout << "Duplicates in list3:"; print_list(find_dups(list3)); }

list find_dups (const list& thelist) { // TODO: Find all duplicates in thelist, and return those values in a list return list(); // stub code }

void print_list (const list& thelist) { // Prints a list of integers separated by spaces, with newline for (list::const_iterator i = thelist.begin(); i != thelist.end(); i++) cout << ' ' << *i; cout << endl; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

Prepare a short profile of Lucy Clifford ?

Answered: 1 week ago

Question

Prepare a short profile of Rosa parks?

Answered: 1 week ago

Question

Prepare a short profile of victor marie hugo ?

Answered: 1 week ago