本文整理汇总了C++中MyList::at方法的典型用法代码示例。如果您正苦于以下问题:C++ MyList::at方法的具体用法?C++ MyList::at怎么用?C++ MyList::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyList
的用法示例。
在下文中一共展示了MyList::at方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: median
CALCAMNT KStats::median(){
int index;
CALCAMNT result;
CALCAMNT *dp;
int bound = 0;
MyList list;
for ( dp=data.first(); dp != 0; dp=data.next() ){
list.inSort(dp);
}
#ifdef DEBUG_STATS
for(int l = 0; l < (int)list.count();l++){
printf("Sorted %Lg\n",*list.at(l));
}
#endif
bound = list.count();
if (bound == 0){
error_flag = TRUE;
return 0.0;
}
if ( bound == 1)
return *list.at(0);
if( bound % 2){ // odd
index = (bound - 1 ) / 2 + 1;
result = *list.at(index - 1 );
}
else { // even
index = bound / 2;
result = ((*list.at(index - 1)) + (*list.at(index)))/2;
}
return result;
}
示例2: computeBC
MyList<double>* BCAlg:: computeBC(MyList<BCUser*> &userList){
//BC Algorithm Execution
for(int i = 0; i < userList.size(); i++){
userList[i]->bc = 0;
}
for(int s = 0; s < userList.size(); s++){
for(int t = 0; t < userList.size(); t++){
delete userList[t]->preds;
userList[t]->preds = new MyList<int>;
userList[t]->numsp = 0;
userList[t]->dist = -1;
userList[t]->delta = 0.0;
}
userList[s]->numsp = 1;
userList[s]->dist = 0;
Stack<BCUser*> myStack;
Queue<BCUser*> myQueue;
myQueue.push_back(userList[s]);
while(!myQueue.empty()){ //BFS searching
BCUser *v = myQueue.front();
myQueue.pop_front();
myStack.push(v);
for(int w = 0; w < v->getFriendList().size(); w++){
BCUser *doubleU = userList[v->getFriendList()[w]];
if(doubleU->dist == -1){
myQueue.push_back(doubleU);
doubleU->dist = v->dist + 1;
}
if(doubleU->dist == v->dist + 1){
doubleU->numsp = doubleU->numsp + v->numsp;
doubleU->preds->push_back(v->getID());
}
}
}
while(!myStack.empty()){
BCUser *w = myStack.top();
myStack.pop();
for(int v = 0; v < w->preds->size(); v++){
userList[w->preds->at(v)]->delta = userList[w->preds->at(v)]->delta + (userList[w->preds->at(v)]->numsp*1.0)/(w->numsp)*(1+w->delta);
}
w->bc = w->bc + w->delta;
}
}
MyList<double> *normals = new MyList<double>(); //Normalize scores below
double minScore = userList[0]->bc;
double maxScore = userList[0]->bc;
for(int i = 0; i < userList.size(); i++){ //Initializes normal values
normals->push_back(-1);
}
for(int i = 1; i < userList.size(); i++){ //Finds min score
if(userList[i]->bc < minScore) { minScore = userList[i]->bc; }
}
for(int i = 1; i < userList.size(); i++){
if(userList[i]->bc > maxScore) { maxScore = userList[i]->bc; } //Finds max score
}
for(int i = 0; i < userList.size(); i++){
(*normals)[userList[i]->getID()] = userList[i]->bc;
}
for(int i = 0; i < normals->size(); i++){
normals->at(i) = (normals->at(i) - minScore)/(maxScore-minScore); //Finishes calculation
}
return normals;
}