本文整理汇总了C++中LList::FirstRight方法的典型用法代码示例。如果您正苦于以下问题:C++ LList::FirstRight方法的具体用法?C++ LList::FirstRight怎么用?C++ LList::FirstRight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LList
的用法示例。
在下文中一共展示了LList::FirstRight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Multi
LongInt* Multi(LongInt* otherInt) //multiplication
{
LongInt *result = new LongInt();
//sign
if(intData->head->value == otherInt->intData->head->value)
result->intData->head->value = 0;
else
result->intData->head->value = 1;
LList* myList = intData;
LNode *myNode = intData->FirstRight();
LList *otherList = otherInt->intData;
//the length of the result
for(int i = 0; i < myList->count + otherList->count; i++)
{
LNode* zeroNode = new LNode();
zeroNode->value = 0;
zeroNode->next = zeroNode->prev = NULL;
result->intData->InsertLeft(zeroNode);
zeroNode = NULL;
}
for(int i = 1; myNode != myList->head; myNode = myNode->prev, i++)
{
LNode* otherNode = otherList->FirstRight();
for(int j = 1; otherNode != otherList->head; otherNode = otherNode->prev, j++)
{
int myValue = myNode->value;
int otherValue = otherNode->value;
int tempResult = myValue * otherValue;
int carry = OverFlow(tempResult);
tempResult = tempResult - carry * (int)pow(10.0, (double)EVERY_NODE_LEN);
LNode* resultNode = result->intData->CountFromRight(i + j - 1);
LNode* carryNode = result->intData->CountFromRight(i + j);
resultNode->value += tempResult; //may carry
int carry2 = OverFlow(resultNode->value);
resultNode->value = resultNode->value - carry2 * (int)pow(10.0, (double)EVERY_NODE_LEN);
carryNode->value += carry + carry2; //may carry
int carry3 = OverFlow(carryNode->value);
carryNode->value = carryNode->value - carry3 * (int)pow(10.0, (double)EVERY_NODE_LEN);
carryNode->prev->value += carry3;
}
}
LNode* delNode = result->intData->head->next;
while(delNode->value == 0)
{
result->intData->head->next = result->intData->head->next->next;
result->intData->head->next->prev = result->intData->head;
delete delNode;
delNode = result->intData->head->next;
}
return result;
}
示例2: Add
LongInt* Add(LongInt* otherInt) //addition
{
LongInt *result = new LongInt();
LList* otherList = otherInt->intData;
LList* resultList = result->intData;
LNode* myNode = intData->FirstRight();
LNode* otherNode = otherList->FirstRight();
int addition = 0;
int carry = 0;
LNode* tempNode;
while(intData->count != otherList->count)
{
LNode* zeroNode = new LNode();
zeroNode->value = 0;
zeroNode->next = zeroNode->prev = NULL;
if(intData->count > otherList->count)
otherList->InsertLeft(zeroNode);
else
intData->InsertLeft(zeroNode);
zeroNode = NULL;
}
if(intData->head->value == otherList->head->value)
{
resultList->head->value = intData->head->value;
while(myNode != intData->head)
{
addition = myNode->value + otherNode->value + carry;
carry = OverFlow(addition);
addition = addition - carry * (int)pow(10.0, (double)EVERY_NODE_LEN);
tempNode = new LNode();
tempNode->value = addition;
tempNode->prev = tempNode->next = NULL;
resultList->InsertLeft(tempNode);
tempNode = NULL;
myNode = intData->NextLeft(myNode);
otherNode = otherList->NextLeft(otherNode);
}
if(carry != 0)
{
LNode* carryNode = new LNode();
carryNode->value = carry;
carryNode->next = carryNode->prev = NULL;
resultList->InsertLeft(carryNode);
}
}
else //opposite sign
{
LList *leftList, *rightList;
int abs = CompAbs(otherInt);
if(abs == 0)
{
LNode* zeroNode = new LNode();
zeroNode->value = 0;
zeroNode->next = zeroNode->prev = NULL;
resultList->InsertLeft(zeroNode);
return result;
}
else if(abs == 1)
{
resultList->head->value = intData->head->value;
leftList = intData;
rightList = otherInt->intData;
}
else
{
resultList->head->value = otherInt->intData->head->value;
leftList = otherInt->intData;
rightList = intData;
}
myNode = leftList->FirstRight();
otherNode = rightList->FirstRight();
carry = 0;
while(myNode != leftList->head)
{
addition = myNode->value - otherNode->value + carry;
if(addition < 0)
{
carry = -1;
addition = addition + (int)pow(10.0, (double)EVERY_NODE_LEN);
}
else
carry = 0;
tempNode = new LNode();
tempNode->value = addition;
tempNode->prev = tempNode->next = NULL;
resultList->InsertLeft(tempNode);
tempNode = NULL;
myNode = leftList->NextLeft(myNode);
otherNode = rightList->NextLeft(otherNode);
//.........这里部分代码省略.........