how to sort integers and characters

how do i start sorting integers and characters
checking for repeats

if i have 12 numbers

1 9 12 13 14 17 18 8 21 1 2 22

causing repeats to be new numbers

an array should be used like this

int y[] = { 1, 9, 12, 13, 14, 17, 18, 8, 21, 1, 2, 22 };

function should check one number to a repeat and make sure repeat
is changed before moving on
I'm not sure I understand what you want with repeats.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
  int xs[] = { 1, 9, 12, 13, 14, 17, 18, 8, 21, 1, 2, 22 };
  cout << "given: "; for (auto x:xs) cout << x << " "; cout << "\n";

  sort( begin(xs), end(xs) );
  cout << "sorted: "; for (auto x:xs) cout << x << " "; cout << "\n";

  auto n = unique( begin(xs), end(xs) ) - begin(xs);
  cout << "duplicates \"removed\": ";
  for (auto i=0; i<n; i++) cout << xs[i] << " ";
  cout << "\n";
}

Hope this helps.
oops didn't put in a repeat number
this fix

int y[] = { 1, 9, 12, 13, 14, 17, 18, 8, 21, 1, 2, 9 };

Last edited on
repeat removed that pretty cool

needed new number for repeat so no repeat

Topic archived. No new replies allowed.