本文整理汇总了C++中addToList函数的典型用法代码示例。如果您正苦于以下问题:C++ addToList函数的具体用法?C++ addToList怎么用?C++ addToList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了addToList函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: concatList
listPo concatList(heapPo H, listPo l1, listPo l2) {
integer len1 = l1->length;
integer len2 = l2->length;
if (len1 == 0)
return l2;
else if (len2 == 0)
return l1;
else {
int root = gcAddRoot(H, (ptrPo) &l1);
gcAddRoot(H, (ptrPo) (&l2));
integer llen = len1 + len2;
listPo reslt = createList(H, llen + llen / 2);
for (integer ix = 0; ix < len1; ix++) {
reslt = addToList(H, reslt, nthEl(l1, ix));
}
for (integer ix = 0; ix < len2; ix++) {
reslt = addToList(H, reslt, nthEl(l2, ix));
}
gcReleaseRoot(H, root);
return reslt;
}
}
示例2: addToList
void BST::addToList(std::vector<std::list<Node*> >& nodeLists, Node* node, int level)
{
//add current node to the list
// check whether we have the list for level is created.
std::vector<std::list<Node*> >::iterator it = nodeLists.begin();
std::list<Node*> list;
for (int i = 0; i < level; i++) {
it++;
}
if (it == nodeLists.end())
nodeLists.push_back(list);
it = nodeLists.begin();
for (int i = 0; i < level; i++) {
it++;
}
if (it == nodeLists.end()) {
std::cout << "WTF" <<std::endl;
return;
}
(*it).push_back(node);
if(node->left)
addToList(nodeLists, node->left, level+1);
if(node->right)
addToList(nodeLists, node->right, level+1);
}
示例3: getTriplesByPerimeter
void getTriplesByPerimeter(triple * t, const uint64_t limit, triple *** const list, uint32_t * const count, uint32_t * const size) {
static const int64_t transformationMatrix[3][3][3] =
{{{ 1,-2, 2}
,{ 2,-1, 2}
,{ 2,-2, 3}}
,{{ 1, 2, 2}
,{ 2, 1, 2}
,{ 2, 2, 3}}
,{{-1, 2, 2}
,{-2, 1, 2}
,{-2, 2, 3}}};
uint32_t i;
uint64_t perimeter_ = perimeter(t);
if(perimeter_ > limit) {
free(t);
return;
}
addToList(t,list,count,size);
for(i=2; i*perimeter_ <= limit; ++i)
addToList(scalarMultiply(i,t),list,count,size);
for(i=0; i<3; ++i)
getTriplesByPerimeter(matrixMultiply((int64_t *)transformationMatrix[i],t)
,limit,list,count,size);
}
示例4: createList
List *add(List *first, List *second){
List *result = createList();
ListElement *currentFirst = first->head->next;
ListElement *currentSecond = second->head->next;
while (currentFirst != nullptr || currentSecond != nullptr){
if (currentFirst == nullptr){
addToList(currentSecond->power, currentSecond->ratio, result);
currentSecond = currentSecond->next;
}
else if (currentSecond == nullptr){
addToList(currentFirst->power, currentFirst->ratio, result);
currentFirst = currentFirst->next;
}
else{
if (currentFirst->power > currentSecond->power){
addToList(currentFirst->power, currentFirst->ratio, result);
currentFirst = currentFirst->next;
}
else if (currentFirst->power < currentSecond->power){
addToList(currentSecond->power, currentSecond->ratio, result);
currentSecond = currentSecond->next;
}
else{
if (currentSecond->ratio + currentFirst->ratio != 0)
addToList(currentSecond->power, currentSecond->ratio + currentFirst->ratio, result);
currentSecond = currentSecond->next;
currentFirst = currentFirst->next;
}
}
}
return result;
}
示例5: clearList
Status LogReader::SetFilter(const char *a_filter, unsigned int a_filterSize,
unsigned int a_maxFindSize, bool a_raw)
{
if (a_filterSize > 0 && a_filter == InvPtr)
return s_invalidParameter;
m_filter = a_filter;
m_filterSize = a_filterSize;
clearList();
StrClose *l_strClose;
if (!a_raw)
{
StrEntry *const l_strEntry = new(std::nothrow) StrEntry;
if (l_strEntry == InvPtr)
return s_memAllocError;
l_strClose = new(std::nothrow) StrClose;
if (l_strClose == InvPtr)
{
delete l_strEntry;
return s_memAllocError;
}
addToList(l_strEntry);
}
m_status = s_ok;
machine();
if (m_status == s_ok && m_list == InvPtr)
{
Substit *const l_substit = new(std::nothrow) Substit(0, true);
if (l_substit == InvPtr)
m_status = s_memAllocError;
else
addToList(l_substit);
}
if (m_status != s_ok)
{
delete l_strClose;
clearList();
}
else
{
if (!a_raw)
addToList(l_strClose);
m_raw = a_raw;
m_maxFindSize = a_maxFindSize;
reset();
}
return m_status;
}
示例6: createLists
void createLists()
{
int iRnd = getRndNumber(0, 10);
lnNode = new ListNode(iRnd, NULL);
ListNode* tmpNode = NULL;
iRnd = getRndNumber(0, 10);
tmpNode = new ListNode(iRnd, NULL);
tmpNode->next = lnNode;
lnNode = tmpNode;
iRnd = getRndNumber(0, 10);
tmpNode = new ListNode(iRnd, NULL);
tmpNode->next = lnNode;
lnNode = tmpNode;
//---------------------------------
iRnd = getRndNumber(0, 10);
lnNodePM = new ListNode(iRnd, NULL);
iRnd = getRndNumber(0, 10);
addToList(iRnd);
iRnd = getRndNumber(0, 10);
addToList(iRnd);
}
示例7: test_addToList_adds_the_given_data_to_the_list_also_increments_the_length
void test_addToList_adds_the_given_data_to_the_list_also_increments_the_length () {
LinkedList list = createList();
int a = 5;
addToList(&list, &a);
assert(list.length == 1);
addToList(&list, &a);
assert(list.length == 2);
}
示例8: builtin
Expr builtin(Type t, const std::string &name, Expr a, Expr b) {
MLVal args = makeList();
args = addToList(args, b.node());
args = addToList(args, a.node());
Expr e(makeExternCall(t.mlval, name, args), t);
e.child(a);
e.child(b);
return e;
}
示例9: test_getLastElement_gives_the_address_of_last_element_in_the_list
void test_getLastElement_gives_the_address_of_last_element_in_the_list () {
LinkedList list = createList();
int a = 5;
int b = 10;
addToList(&list, &a);
addToList(&list, &b);
Element *element = getLastElement(list);
assert(*(int *)(element->value) == 10);
}
示例10: iteration
void iteration(struct GOL *gol)
{
struct Cell *cell;
unsigned int i;
unsigned int count;
unsigned int threadNum;
double ccTime, wupTime, thTime;
// TODO: it can be multithread?
reviveCells(&gol->toRevive[0], gol->world);
killCells(&gol->toKill[0], gol->world);
ccTime = startMeasurement();
#pragma omp parallel shared(gol) private(cell, count, threadNum, thTime)
{
thTime = startMeasurement();
threadNum = omp_get_thread_num();
for (cell = wit_first_split(&count, threadNum, gol->world);
wit_done_split(count, gol->world);
cell = wit_next_split(cell, &count, gol->numThreads))
{
switch (checkRule(cell, gol->rule)) {
case GOL_REVIVE:
addToList(cell, &gol->toRevive[threadNum]);
break;
case GOL_KILL:
addToList(cell, &gol->toKill[threadNum]);
break;
case GOL_SURVIVE:
case GOL_KEEP_DEAD:
default:
break;
}
}
endMeasurement(thTime, threads[threadNum], gol->stats);
}
endMeasurement(ccTime, cellChecking, gol->stats);
wupTime = startMeasurement();
// Add lists
for (i = 0; i < gol->numThreads; ++i) {
reviveCells(&gol->toRevive[i], gol->world);
freeList(&gol->toRevive[i]);
}
// Free lists
for (i = 0; i < gol->numThreads; ++i) {
killCells(&gol->toKill[i], gol->world);
freeList(&gol->toKill[i]);
}
endMeasurement(wupTime, worldUpdate, gol->stats);
}
示例11: searchExactManyCoresK
// Exact k-NN search with the RBC. This version works better on computers
// with a high core count (say > 4)
void searchExactManyCoresK(matrix q, matrix x, matrix r, rep *ri, unint **NNs, real **dNNs, unint K){
unint i, j, k;
unint **repID = (unint**)calloc(q.pr, sizeof(*repID));
for(i=0; i<q.pr; i++)
repID[i] = (unint*)calloc(K, sizeof(**repID));
real **dToReps = (real**)calloc(q.pr, sizeof(*dToReps));
for(i=0; i<q.pr; i++)
dToReps[i] = (real*)calloc(K, sizeof(**dToReps));
intList *toSearch = (intList*)calloc(r.pr, sizeof(*toSearch));
for(i=0;i<r.pr;i++)
createList(&toSearch[i]);
bruteKHeap(r,q,repID,dToReps,K);
#pragma omp parallel for private(j,k)
for(i=0; i<r.pr/CL; i++){
unint row = CL*i;
real temp[CL];
for(j=0; j<q.r; j++ ){
for(k=0; k<CL; k++){
temp[k] = distVec( q, r, j, row+k );
}
for(k=0; k<CL; k++){
//dToRep[j] is current UB on dist to j's NN
//temp - ri[i].radius is LB to dist belonging to rep i
if( row+k<r.r && 3.0*dToReps[j][K-1] >= temp[k] && dToReps[j][K-1] >= temp[k] - ri[row+k].radius)
addToList(&toSearch[row+k], j); //query j needs to search rep
}
}
for(j=0;j<CL;j++){
if(row+j<r.r){
while(toSearch[row+j].len % CL != 0)
addToList(&toSearch[row+j],DUMMY_IDX);
}
}
}
bruteListK(x,q,ri,toSearch,r.r,NNs,dToReps,K);
for(i=0; i<q.r; i++){
for(j=0; j<K; j++)
dNNs[i][j]=dToReps[i][j];
}
for(i=0;i<q.pr;i++)
free(dToReps[i]);
free(dToReps);
for(i=0;i<r.pr;i++)
destroyList(&toSearch[i]);
free(toSearch);
for(i=0;i<q.pr;i++)
free(repID[i]);
free(repID);
}
示例12: main
int main() {
int data1,data2,data3,data4,data5;
int nonData = 6;
int * pFind = NULL;
List test = NULL;
initList(&test);
data1 = 10;data2 = 20;data3 = 30;data4 = 40;data5 = 50;
addToList(test, (void*)&data1);
addToList(test, (void*)&data2);
addToList(test, (void*)&data3);
addToList(test, (void*)&data4);
addToList(test, (void*)&data5);
displayList(test);
printf("%s","Searching for 30");
pFind = (int*)findInList(test, (void*)&data3, intGreater);
if (pFind)
{
printf("%s%d","\nFound data value: ", *pFind);
}
else {
printf("%s","\nData not found");
}
printf("%s","\nSearching for 99 (shouldn't be in list)");
pFind = (int*)findInList(test, (void*)&nonData, intGreater);
if (pFind)
{
printf("%s%d","\nFound data value: ", *pFind);
}
else {
printf("%s","\nData not found");
}
printf("%s","\nremoving one item then displaying\n");
removeFirst(test);
displayList(test);
printf("%s","removing all items then displaying\n");
deleteList(test);
displayList(test);
printf("%s","Attempting to remove from an empty list\n");
removeFirst(test);
displayList(test);
cleanupList(&test);
printf("%s","All tests complete\n");
return 0;
}
示例13: test_getElementAt_gives_the_address_of_the_element_at_given_index
void test_getElementAt_gives_the_address_of_the_element_at_given_index () {
LinkedList list = createList();
int a = 5;
int b = 10;
void *element;
addToList(&list, &a);
addToList(&list, &b);
element = getElementAt(list, 1);
assert(*(int *)element == 10);
}
示例14: test_getElementAt_gives_the_NULL_for_a_given_invalid_index
void test_getElementAt_gives_the_NULL_for_a_given_invalid_index () {
LinkedList list = createList();
int a = 5;
int b = 10;
void *element;
addToList(&list, &a);
addToList(&list, &b);
element = getElementAt(list, 9);
assert(element == NULL);
}
示例15: test_indexOf_returns_the_index_of_given_address_of_the_value
void test_indexOf_returns_the_index_of_given_address_of_the_value () {
LinkedList list = createList();
int a = 5;
int b = 10;
void *element;
addToList(&list, &a);
addToList(&list, &b);
int index = indexOf(list, &b);
assert(index == 1);
}