📄 pex7_6.cpp
字号:
#include <iostream.h>
#pragma hdrstop
#include "datainfo.h"
#include "utils.h"
void main(void)
{
// new objects are read into w
DataInfo<int> w;
int inputsize, listsize = 0;
int index, i;
// prompt for the number of elements to input
cout << "Enter the input count: ";
cin >> inputsize;
// create a DatInfo array of inputsize objects
DataInfo<int> *dataList = new DataInfo<int> [inputsize];
cout << "Enter the list of numbers: ";
for (i = 0; i < inputsize; i++)
{
// read a number and check if it is already in the list
cin >> w;
if ((index = SeqSearch(dataList,listsize,w)) != -1)
// if yes, increment the frequency count
dataList[index].Increment();
else
{
// otherwise add it to the array
dataList[listsize] = w;
// increment the number of distinct values
listsize++;
}
}
// sort the array by frequency and output the sorted list
ExchangeSort(dataList,listsize);
for (i=0;i < listsize;i++)
cout << dataList[i];
}
/*
Enter the input count: 10
Enter the list of numbers: 8 2 9 8 2 9 2 2 5 1
5: 1
1: 1
8: 2
9: 2
2: 4
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -