本文整理汇总了C++中graph::push方法的典型用法代码示例。如果您正苦于以下问题:C++ graph::push方法的具体用法?C++ graph::push怎么用?C++ graph::push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph
的用法示例。
在下文中一共展示了graph::push方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadVector
void loadVector(graph &pass, string name)
{
ifstream fin;
fin.open(name.c_str());
string temp;
string xx,yy;
int size = 0;
bool first = true, xflag = false, yflag = false;
if(name.size() != 0)
{
while(!fin.eof())
{
temp = "";
fin >> temp;
if(temp.size()!= 0)
{
first = true;
xx="";
yy="";
size = temp.size();
for (int x = 0; x < size; ++x)
{
if(temp.at(x) == ',')
{
first = false;
}
if(temp.at(x) == '-')
{
if(first)
{
xflag = true;
}
else
{
yflag = true;
}
}
if(temp.at(x)-48 > -1 && temp.at(x)-48 < 10) // checks if it is a number
{
if(first)
{
xx += temp.at(x);
}
else
{
yy += temp.at(x);
}
}
}
//cout << xx << " " << yy << endl;
pass.push(stringToInt(xx,xflag), stringToInt(yy,yflag));
xflag = false;
yflag = false;
}
}
}
else
示例2: t_thread_bfs_1
int t_thread_bfs_1()
{
// setup graph
static list<int> fnode;
static graph g(5);
static map<int, int> xmap;
struct thread_bfs *thr_bfs;
numTerm = 0;
int numCre = 0;
g.push(1, 2, 0);
g.push(1, 4, 0);
g.push(1, 5, 0);
g.push(2, 3, 0);
g.push(3, 5, 0);
g.push(4, 3, 0);
g.push(4, 5, 0);
pthread_t thr;
// main thread is waiting for the list to be updated, and
fnode.push_back(1);
xmap[1]++; // mark visited. Otherwise you might end up with revisit the node
bool done = false;
while (!done) {
int err = pthread_mutex_lock(&mtx);
if (err)
cout << " error in mutex_lock " << endl;
// if work to do in the Q then create a thread do a task
// Or, I can create as much tasks as possible by taking all the tasks in the Q
if (!fnode.empty()) {
int n = fnode.front();
fnode.pop_front();
cout << endl << "visited " << n << endl;
// setup data for the worker thread to access
thr_bfs = new struct thread_bfs;
thr_bfs->pfnode = &fnode;
thr_bfs->pg = &g;
thr_bfs->pmap = ⟼
thr_bfs->node = n;
int err = pthread_create(&thr, NULL, threadFunc1, thr_bfs); // at the moment, I am not worry about joining the created thread.
if (err)
cout << " error in creating thread " << endl;
numCre++; // num created threads
} else if (numCre > numTerm) {
// we do not have anything in the Q but worker threads are pending
// wait for signal from the thread to avoid busy waiting
cout << endl << "wait for new Data" << endl;
err = pthread_cond_wait(&cond, &mtx);
if (err)
cout << " error in cond_wait " << endl;
} else if (numCre == numTerm) {
done = true; // if all threads are terminated and nothing to do more.
cout << endl << "processed all" << endl;
} else {
cout << "error" << endl;
}
err = pthread_mutex_unlock(&mtx);
if (err)
cout << " error in mutex_unlock " << endl;
}
}