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

📄 pex7_7.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 CPP
字号:
#include <iostream.h>
#pragma hdrstop

#include "datainfo.h"
#include "utils.h"		// for SeqSearch
#include "wex7_5.h"		// for InsertOrder

// delete the list element at position index
template <class T>
void Delete(DataInfo<T> dataList[],int listsize,int index)
{
	// move the list elements at positions index+1 ... listsize-1
	// left one location
	for(int i=index+1;i < listsize;i++)
		dataList[i-1] = dataList[i];
}

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 number is in the list, increment the frequency count
            w = dataList[index];
            w.Increment();
            // remove the element from the list, since its position
            // may change in the ordered list
            Delete(dataList,listsize,index);
            // reinsert w into the list
			InsertOrder(dataList,listsize-1, w);
		}
        else
        {
			// insert w into the list ordered by frequency
      		InsertOrder(dataList, listsize, w);
      		// increment the number of distinct values
            listsize++;
        }
    }
           
	// output the sorted list
    for (i=0;i < listsize;i++)
        cout << dataList[i];
}

/*

Enter the input count: 15
Enter the list of numbers: 1 2 3 5 2 1 6 3 5 5 2 1 6 7 3
7: 1
6: 2
3: 3
1: 3
2: 3
5: 3
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -