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

📄 main.cpp

📁 一个我的数据结构解题集合
💻 CPP
字号:
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include "IoUtils.h"
#include "FreqList.h"
using namespace std;


int main() {
	int noErrors = 0;

	cout << "FreqList::search:\n"
		 << "\t为方便起见, 本程序先创建一个FreqList, 并在其中填充10个100以内的随机数\n"
		 << "\t然后打印该链表, 随后让用户输入想要查找的元素,\n"
		 << "\t每次查找后首先打印访问结果 (即是否找到),\n"
		 << "\t然后打印该链表, 以便观察其变化\n"
		 << endl;


	FreqList<int> list;

	srand((unsigned int)time(NULL));

	int i=0;
	while (i<10) {
		int val = rand()%99 + 1;
		if ( list.has(val) ) continue;
		list.insert(val);
		++i;
	}
	list.print();

	
	while (true) try {

		cout << "请输入想要查找的元素值 (0: 退出): " << flush;
		int val = getInteger();

		if (val == 0)
			return noErrors;

		cout << "\n";
		if ( list.search(val) )
			cout << "找到元素 " << val << "\n";
		else
			cout << "未找到元素 " << val << "\n";
		cout << endl;

		list.print();

	} catch (const std::exception& e) {
		cerr << "捕捉到异常!" << endl;
		cerr << e.what() << endl;
		++noErrors;
	}

	return noErrors;
} // main()

⌨️ 快捷键说明

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