本文整理汇总了C++中MyList::size方法的典型用法代码示例。如果您正苦于以下问题:C++ MyList::size方法的具体用法?C++ MyList::size怎么用?C++ MyList::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyList
的用法示例。
在下文中一共展示了MyList::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
void GMLWriter::write(char* n, MyList<BCUser*> list)
{
ofstream outputFile;
outputFile.open(n);
if (outputFile.is_open())
{
outputFile<< "graph [\n";
for (int i= 0; i<list.size(); i++)//gets info for each User
{
outputFile<<" node ["<<endl;
outputFile<<" id "<<list[i]->getIdNum()<<endl;
outputFile<<" name \""<<list[i]->getName()<<"\""<<endl;
outputFile<<" age "<<list[i]->getAge()<<endl;
outputFile<<" zip "<<list[i]->getZip()<<endl;
outputFile<<" ]"<<endl;
}
for (int j = 0; j < list.size(); j++)
{
if (list[j]->getFriendId().size()!=0)//get info for each edge
{
for (int k=0; k<list[j]->getFriendId().size(); k++ ){
outputFile<<" edge ["<<endl;
outputFile<<" source "<< list[j]->getIdNum()<<endl;
outputFile<<" target "<< list[j]->getFriendId()[k]<<endl;
outputFile<<" ]"<<endl;
}
}
}
outputFile<<"]"<<endl;
outputFile.close();
}
}
示例2: main
int main ()
{
//We will create a buffer of 1000 bytes to store a list
managed_heap_memory heap_memory(1000);
MyList * mylist = heap_memory.construct<MyList>("MyList")
(heap_memory.get_segment_manager());
//Obtain handle, that identifies the list in the buffer
managed_heap_memory::handle_t list_handle = heap_memory.get_handle_from_address(mylist);
//Fill list until there is no more memory in the buffer
try{
while(1) {
mylist->insert(mylist->begin(), 0);
}
}
catch(const bad_alloc &){
//memory is full
}
//Let's obtain the size of the list
MyList::size_type old_size = mylist->size();
//<-
(void)old_size;
//->
//To make the list bigger, let's increase the heap buffer
//in 1000 bytes more.
heap_memory.grow(1000);
//If memory has been reallocated, the old pointer is invalid, so
//use previously obtained handle to find the new pointer.
mylist = static_cast<MyList *>
(heap_memory.get_address_from_handle(list_handle));
//Fill list until there is no more memory in the buffer
try{
while(1) {
mylist->insert(mylist->begin(), 0);
}
}
catch(const bad_alloc &){
//memory is full
}
//Let's obtain the new size of the list
MyList::size_type new_size = mylist->size();
//<-
(void)new_size;
//->
assert(new_size > old_size);
//Destroy list
heap_memory.destroy_ptr(mylist);
return 0;
}
示例3: main
int main() {
MyList<int> ml;
int choose;
int pos, entry;
while (1) {
cout << "1.insert 2.remove 3. replace 4.size 5.empty 6.retrive 7.display" << endl;
cin >> choose;
switch (choose) {
case 1:
cin >> pos >> entry;
ml.insert(pos, entry);
break;
case 2:
cin >> pos;
ml.remove(pos, entry);
cout << entry << endl;
break;
case 3:
cin >> pos >> entry;
ml.replace(pos, entry);
break;
case 4:
cout << ml.size() << endl;
break;
case 5:
cout << ml.empty() << endl;
break;
case 6:
cin >> pos;
ml.retrieve(pos, entry);
cout << entry << endl;
break;
case 7:
ml.display();
}
}
}
示例4: main
int main ()
{
const char *FileName = "file_mapping";
const std::size_t FileSize = 1000;
file_mapping::remove(FileName);
try{
std::size_t old_size = 0;
managed_mapped_file::handle_t list_handle;
{
managed_mapped_file mfile_memory(create_only, FileName, FileSize);
MyList *mylist = mfile_memory.construct<MyList>("MyList")
(mfile_memory.get_segment_manager());
//Obtain handle, that identifies the list in the buffer
list_handle = mfile_memory.get_handle_from_address(mylist);
//Fill list until there is no more room in the file
try{
while(1) {
mylist->insert(mylist->begin(), 0);
}
}
catch(const bad_alloc &){
//mapped file is full
}
//Let's obtain the size of the list
old_size = mylist->size();
}
//To make the list bigger, let's increase the mapped file
//in FileSize bytes more.
managed_mapped_file::grow(FileName, FileSize*2);
{
managed_mapped_file mfile_memory(open_only, FileName);
//If mapping address has changed, the old pointer is invalid,
//so use previously obtained handle to find the new pointer.
MyList *mylist = static_cast<MyList *>
(mfile_memory.get_address_from_handle(list_handle));
//Fill list until there is no more room in the file
try{
while(1) {
mylist->insert(mylist->begin(), 0);
}
}
catch(const bad_alloc &){
//mapped file is full
}
//Let's obtain the new size of the list
std::size_t new_size = mylist->size();
assert(new_size > old_size);
//Destroy list
mfile_memory.destroy_ptr(mylist);
}
}
catch(...){
file_mapping::remove(FileName);
throw;
}
file_mapping::remove(FileName);
return 0;
}
示例5: 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;
}