Exemple #1
0
 void topo_sort(IV &in, IV &order) {
     IQ q;
     for (int i = 0; i < n; ++i) if (in[i] == 0) q.push(i);
     order.clear();
     while (! q.empty()) {
         int v = q.front(); q.pop();
         order.push_back(v);
         cFor (EL, e, adj[v])
             if (--in[e->v] == 0) q.push(e->v);
     }
 }
Exemple #2
0
int main() {
	const map<string, constants> comands = { { "add", constants::add },{ "get", constants::get },{ "del", constants::del } };

	wstring libName;
	wcin >> libName;
	LPCWSTR wLibName = libName.c_str();
	HINSTANCE lib = LoadLibrary(wLibName);
	if (!lib) {
		cout << "Library not found" << endl;
		return 0;
	}
	int n;
	cin >> n;
	string line, word;
	IQ<> *(*getQueue)() = (IQ<> *(*)())GetProcAddress(lib, "GetSomeIQ");
	if (!getQueue)
		return 0;
	IQ<> *pQueue = getQueue();
	if (!pQueue)
		return 0;
	cin.get();
	for (int i = 0; i < n; ++i) {
		getline(cin, line);
		istringstream ss(line);
		ss >> word;
		try {
			switch (comands.at(word)) {
			case constants::add:
				int value;
				ss >> value;
				pQueue->push(value);
				break;
			case constants::get:
				try {
					cout << pQueue->top() << endl;
				}
				catch (...) {
					cout << "Queue is empty" << endl;
				}
				break;
			case constants::del:
				pQueue->pop();
				break;
			}
		}
		catch (...) {
			cout << "Unknown command" << endl;
		}
	}
	FreeLibrary(lib);
	system("pause");
	return 0;
}