怎么整理数列
Your program will do the following:1. Read in a positive integer n representing the number of values the user will enter.
2. Then read in n double values into an array. You may assume that n <= 1000, i.e., the
user will enter at most 1000 numbers.
3. Use an algorithm discussed in class to sort this array from smallest to largest.
4. Then print out for each distinct value (from smallest to largest), how many times it
appeared in the sequence.
这是国外大学的一个作业,小弟只会把数列以顺序的形式来输出,但是这个要求把数列里面的相同元素分为一类,然后再输出,我是第一次学这个,完全不懂,希望大家能帮个忙,
#include <iostream>
using namespace std;
int main () {
int i;
int n;
int j;
double decimal[1000];
int counter;
int index;
double temp;
int constant = 0;
cout << "Enter a positive integer:" << "\n";
cin >> n;
cout << "Enter " << n << " numbers:" << "\n";
for (i = 0; i < n; i = i + 1) {
cin >> decimal[i];
}
for (i = 0; i < n-1; i = i + 1) {
index = i;
for (j = i + 1; j < n; j = j + 1) {
if (decimal[index] > decimal[j]) {
index = j;
}
}
temp = decimal[i];
decimal[i] = decimal[index];
values[index] = temp;
}
for (counter = 0;counter < n) {
for (i = 0;i < n;i = i + 1) {
return 0;
}
这是我写完的一段,我现在在想接下来怎么写,