Ejemplo n.º 1
0
//***********************************************************************
void inpSet(HT& T, char name)
{
	T.clear();
	short size, t;
	cout << "Ввод множества " << name << endl;
	cout << "Введите количество элементов от 0 до 16:" << endl;
	do {
		cin.clear();
		cin.sync();
		cin >> size;
		if (size < 0 || size>16 || cin.fail())
			cout << "Число от 0 до 16!\nВведите повторно:";
	} while (size < 0 || size>16 || cin.fail());
	cout << "Введите элементы множества от 0 до 99 без повторов" << endl;
	for (int i = 0; i < size;) {
		cin.clear();
		cin.sync();
		cout << i << "-е число " << name << ":";
		cin >> t;
		if (t<0 || t>99 || cin.fail())
			cout << "Число от 0 до 99!\nВведите другое значение\n";
		else
			T.insert(HT::value_type(t, i));
			++i;
	}
	cout << endl;
}
Ejemplo n.º 2
0
//***********************************************************************
void genSet(HT& T)
{
	T.clear();
	int t = rand() % (arrPower + 1);
	for (int i = 0; i < t; ++i) {
		T.insert(HT::value_type((rand() % hPower + 1), i));
	}
}
Ejemplo n.º 3
0
void mapOr(const HT& leftExp, const HT& rightExp, HT& result)
{
	result.clear();
	vector<int> vl(leftExp.size()), vr(rightExp.size()), vm;
	transform(leftExp.begin(), leftExp.end(), vl.begin(), keySel);   
	transform(rightExp.begin(), rightExp.end(), vr.begin(), keySel); 
	sort(vl.begin(), vl.end());
	sort(vr.begin(), vr.end());
	set_union(vl.cbegin(), vl.cend(), vr.cbegin(), vr.cend(), inserter(vm, vm.begin()));
	int i=0;
	for (auto it = vm.cbegin(); it != vm.cend(); ++it, ++i)
		result.insert(HT::value_type((*it), i));
}
Ejemplo n.º 4
0
//***********************************************************************
int fileSet(HT& T, char name='a')
{
	T.clear();
	FILE* file;
	int size, t;
	char n[6] = " .txt";
	n[0] = name;
	if (!(file = fopen(n, "r")))
		return 1;         //Файла не существует
	fseek(file, 0, SEEK_END);
	if (!ftell(file))
		return 2;         //Файл пустой
	rewind(file);
	fscanf(file, "%d", &size);
	for (int i = 0; i<size; ++i)
	{
		fgetc(file);
		fscanf(file, "%d", &t);
		T.insert(HT::value_type(t, i));
	}
	fclose(file);
	return 0;
}
Ejemplo n.º 5
0
 /** Removes all the elements. */
 void clear() { m_ht.clear(); }