Write function for removing duplicate elements from a given array and sort that array. (Without using inbuilt functions). For Example: Array = {2, 1, 3, 2, 4, 4, 6, 5, 6} Output = {1, 2, 3, 4, 5, 6}
1
Expert's answer
2013-06-10T08:48:36-0400
#include <iostream> using namespace std;
int main() { cout << "Input array length: "; int n; cin >> n; int a[100]; for (int i = 0; i < n; i++) { & cout << "Input element " << i << ": "; & cin >> a[i]; } for (int i = 0; i < n; i++) & for (int j = 0; j < n-1; j++) if (a[j] > a[j+1]) swap(a[j], a[j+1]); for (int i = 1; i < n; i++) { & if (a[i] == a[i-1]) { for (int j = i; j < n-1; j++) a[j] = a[j+1]; --n; --i; & } }
cout << "Resulting array: " << endl; for (int i = 0; i < n; i++) & cout << a[i] << " "; cout << endl; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment