Question

Write a function named "eliminate_duplicates" that takes an array of integers in random order and eliminates...

Write a function named "eliminate_duplicates" that takes an array of integers in random order and eliminates all the duplicate integer integers in the array. The function should take two arguments: (1) an array of integers; (2) an integer that tells the number of cells in the array. The function should return the number of distinct integers in the array.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;
int eliminateDuplicates(int array[], int size);
int main()
{
const int MAX_SIZE = 10;
int numSeq[MAX_SIZE] = { 1, 3, 5, 7, 9, 10, 7, 12, 13, 7};
int result;
result = eliminateDuplicates(numSeq, MAX_SIZE);
cout << endl << "Result is " << result << " numbers." << endl;
return 0;
}
int eliminateDuplicates(int array[], int size)
{
int *dataBuffer = new int[size];
int dataCount = 0;
bool found = false;
memset(dataBuffer, 0, sizeof(int)*size);
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
if (array[i] == dataBuffer[j])
found = true;
if (!found)
{
dataBuffer[dataCount] = array[i];
dataCount++;
}
found = false;
}
for (int i = 0; i < dataCount; i++)
cout << dataBuffer[i] << " ";
delete[] dataBuffer;
return dataCount;
}

Add a comment
Know the answer?
Add Answer to:
Write a function named "eliminate_duplicates" that takes an array of integers in random order and eliminates...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a function named findTarget that takes three parameters: numbers, an array of integers -...

    1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...

  • Write a function named stats, that takes an array and the number of elements in the...

    Write a function named stats, that takes an array and the number of elements in the array as arguments. It must compute and print the minimum value in the array, maximum value in the array and the average value of all the values inside the array. Your function MUST be named stats Your function has two parameters in the following order: an array of type double The number of elements in the array, type int Your function should NOT return...

  • Write a function named findTarget that takes three parameters: - numbers, an array of integers -...

    Write a function named findTarget that takes three parameters: - numbers, an array of integers - size, an integer representing the size of array - target, a number The function returns true if the target is inside array and false otherwise

  • In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array...

    In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...

  • 1.) Write a function called canMakeSum() that takes a sorted array of n integers and determines...

    1.) Write a function called canMakeSum() that takes a sorted array of n integers and determines whether two distinct elements of the array add up to some specified value, "key". If so, return 1. Otherwise, return 0. The function signature is: int canMakeSum(int *array, int n, int key);

  • Write a C++ function that takes a pointer to an array of integers as a parameter...

    Write a C++ function that takes a pointer to an array of integers as a parameter and return the number of prime integers in the array. Write main() program to test the function.

  • Write a function named numPerfect that takes as parameters: an array of integer scores between zero...

    Write a function named numPerfect that takes as parameters: an array of integer scores between zero and 100 (inclusive) the size of the array and returns the number of perfect scores in the array. Also write a main function that creates and initializes an array of ints (in the appropriate range), calls the function with that array, and prints out the return value.

  • (C++) Write a function, remove, that takes three parameters: an array of integers, the number of...

    (C++) Write a function, remove, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, removeItem). The function should find and delete the first occurrence of removeItem in the array. (Note that after deleting the element, the number of elements in the array is reduced by 1.) Assume that the array is unsorted. Also, write a program to test the function. Your program should prompt the user to enter 10 digits...

  • JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...

    JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...

  • USING C++: Write a function that given a 2D dynamic array of integers, will return the...

    USING C++: Write a function that given a 2D dynamic array of integers, will return the number of elements whose absolute value is smaller than a given value x. The function should take as arguments (in this order): a pointer to the array (i.e., 2D dynamic array) the number of rows the number of columns the given value The function should return the number of elements smaller in absolute value than epsilon E.g. if A={{0.2, -0.1, 3.4},{4.4, 0, -2}} and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT