本文整理汇总了C++中MyList类的典型用法代码示例。如果您正苦于以下问题:C++ MyList类的具体用法?C++ MyList怎么用?C++ MyList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MyList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: MyList
template <class Type> bool MyList<Type>::push(Type _element, const int &_position){
if(id == _position){
MyList<Type> *newElement = new MyList(_element);
newElement->setID(id);
newElement->setNext(this);
newElement->setPrevious(previous);
// std::cout<<"created\n";
if(previous!=NULL){
previous->setNext(newElement);
}
setPrevious(newElement);
// std::cout<<"links set\n";
this->changeID(id + 1);
// std::cout<<"id changed\n";
return true;
}
else{
if(next != NULL){
return next->push(_element, _position);
}
else{
return false;
}
}
}
示例3: count
void Test_MyList::count()
{
MyList B;
B.addLast(1);
QCOMPARE(B.count(), 1);
}
示例4:
friend MyList<T> operator + (const MyList<T> &list_1, const T &item)
//add an item to the end of list_1 to create a new list and return it
{
MyList tmplist = list_1;
tmplist.push_back(item);
return tmplist;
}
示例5: addLast
void Test_MyList::addLast()
{
MyList A;
A.addLast(1);
QCOMPARE(A.getItem(0), 1);
A.addLast(2);
QCOMPARE(A.getItem(1), 2);
}
示例6: main
int main(int argc, char** argv){
MyList<string> args = mkArgs ( argc, argv) ;
return ({ MyList< int > numbers = ({ MyList < int > temp( 1,10 ); temp;});
MyList< int > squaredNumbers = (numbers.map(square));
MyList< int > evenSquaredNumbers = ( squaredNumbers.filter(even));
( ({ int p1 = ({ cout << (squaredNumbers) << endl ; cout.good() ? 0 : 1 ; }) ;
int p2 = ({ cout << (evenSquaredNumbers) << endl ; cout.good() ? 0 : 1 ; }) ;
示例7: Initialize
void FixedSet::Initialize(const vector<int>& numbers)
{
size_t sizeOfSecondTables = 0;
size_t tableSize = numbers.size();
MyList<size_t> secondTablesForRebuild;
/* clock_t t1 = clock();*/
secondHashTables.resize(tableSize);
// clock_t t2 = clock();
// cout << (double)(t2 - t1) / CLOCKS_PER_SEC << endl;
generateUniversalHashFunction(tableSize, primeNumber, hash);
for (size_t index = 0; index < tableSize; ++index)
{
size_t hashValue = hash(numbers[index]);
if (!secondHashTables[hashValue].insert(numbers[index]))
{
if (!secondHashTables[hashValue].isNeedRebuild())
{
secondHashTables[hashValue].setRebuild(true);
secondTablesForRebuild.pushFront(hashValue);
}
--sizeOfSecondTables;
}
else
{
++sizeOfSecondTables;
}
}
MyNode<size_t>* it = secondTablesForRebuild.getBegin();
for (; it != 0 && !secondTablesForRebuild.isEmpty(); it = it->next)
{
size_t indexOfSecondHashTable = it->item;
secondHashTables[indexOfSecondHashTable].rebuild();
size_t secondTableSize = secondHashTables[indexOfSecondHashTable].getSize();
sizeOfSecondTables += secondTableSize;
}
if (sizeOfSecondTables > 4 * tableSize)
{
for (size_t index = 0; index < tableSize; ++index)
{
if (!secondHashTables[index].isEmpty())
{
secondHashTables[index].clear();
secondHashTables[index].deleteKeys();
secondHashTables[index].setRebuild(false);
secondHashTables[index].setSize(0);
secondHashTables[index].setEmpty(true);
}
}
Initialize(numbers);
}
}
示例8: main
int main(int argc, char** argv) {
MyList myList;
myList.append(2);
myList.insertN(1,2);
myList.insertN(3,3);
myList.prepend(0);
myList.display();
return 0;
}
示例9:
friend MyList<T> operator + (const MyList<T> &l1, const T &item){
MyList<T> tmp;
tmp.n = l1.n + 1;
int t = tmp.get_SIZE();
while( t < tmp.n)
tmp.double_space();
tmp[l1.n] = item;
return tmp;
}
示例10: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
int cnt;
MyList list;
list.Init();
list.GetResult();
return 0;
}
示例11: MyList
MyList(const MyList &l):size(l.get_size()),len(l.get_size()){
// deep copy the other MyList
a = new T [size];
try{
if (a==NULL) throw (AlloFail());
}
catch(AlloFail){
cerr << "Allocation failure" << endl;
exit(1);
}
for (long i=0; i<len; ++i){
a[i] = l[i];
}
}
示例12: Find
int RedBlackTree::Remove(const char * szStr, int Offset)
{
MyList *lst = Find(szStr) ;
unsigned int hashValue = crc32(szStr) ;
if (lst != NULL && lst->GetSize() > 1)
{
lst->Delete(Offset) ;
return 1 ;
}
else if (lst != NULL)
{
Delete(m_pRoot, hashValue) ;
return 1 ;
}
return 0;
}
示例13: createListNode
/*
* The method takes a string of characters and for each character calculates the char frequency.
* Than creates a list of nodes for binary tree
*
* @param charStr The character string
* @return The list of nodes sorted by char frequency
*/
MyList<Node> createListNode(string *charStr){
MyUnordered_map<char, int> symbols;
for (size_t i = 0; i < charStr->size(); i++){
symbols[charStr->at(i)] = 0;
}
for (size_t i = 0; i < charStr->size(); i++){
symbols[charStr->at(i)]++;
}
MyList<Node> listNode;
for (auto it = symbols.begin(); it != symbols.end(); ++it){
Node node(it -> value, it -> key);
listNode.push_back(node);
}
listNode.sort();
return listNode;
}
示例14: 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;
}
示例15: main
int main(){
MyList<double> list;
//std::cout<<"init\n";
list.pushBack(1.0);
//std::cout<<"pushBack\n";
list.push(2.0, 0);
list.push(3.0, 0);
list.push(4.0, 0);
list.push(4.0, 0);
list.push(5.0, 0);
list.popBack();
list.show();
list.push(6.0, 0);
list.push(7.0, 0);
list.push(8.0, 0);
list.show();
//std::cout<<"push\n";
return 0;
}