⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pex7_6.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 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 + -