当前位置: 首页>>代码示例>>C++>>正文


C++ LList::FirstRight方法代码示例

本文整理汇总了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;

	}
开发者ID:jasminelu,项目名称:LongInt,代码行数:64,代码来源:CS610Project1.cpp

示例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);
//.........这里部分代码省略.........
开发者ID:jasminelu,项目名称:LongInt,代码行数:101,代码来源:CS610Project1.cpp


注:本文中的LList::FirstRight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。