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


C++ ListElement::setNext方法代码示例

本文整理汇总了C++中ListElement::setNext方法的典型用法代码示例。如果您正苦于以下问题:C++ ListElement::setNext方法的具体用法?C++ ListElement::setNext怎么用?C++ ListElement::setNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ListElement的用法示例。


在下文中一共展示了ListElement::setNext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

bool LinkedList<T>::insertAtPos(T data, int pos)
{
	ListElement<T> *nodeToInsert = new ListElement<T>(data);
	if (nodeToInsert == nullptr) return false;

	// If list is empty and position is not the 
	// begining of the list return false. 
	if (isEmpty() && pos != 0) {
		return false;
	}

	ListElement<T> *curr = _head;
	// iterate until we are at pos - 1
	while (curr != nullptr && pos != 1) {
		curr = curr->getNext();
		pos--;
	}

	// insert the ListElement<T>
	if (pos == 1) {
		nodeToInsert->setNext(curr->getNext());
		curr->setNext(nodeToInsert);
		return true;
	}
	return false;
}
开发者ID:ajaykarri,项目名称:DataStructures,代码行数:26,代码来源:SinglyLinkedListTemplate.cpp

示例2: addAfterN

void List::addAfterN(int nPos, int inValue)
{
	if (mLength >= nPos) {
		ListElement *additional = new ListElement(inValue);
		ListElement *current = mHead;
		for (int i = 1; i < nPos; i++) {
			current = current->getNext();
		}
		additional->setNext(current->getNext());
		current->setNext(additional);
		mLength++;
	}
}
开发者ID:AirVan21,项目名称:CPP,代码行数:13,代码来源:List.cpp

示例3: append

void List::append(int inValue)
{
	ListElement *updateHead = new ListElement(inValue);
	if (mLength == 0) {
		mHead = updateHead;
		mTail = updateHead;
	}
	else {
		updateHead->setNext(mHead);
		mHead = updateHead;
	}
	mLength++;
}
开发者ID:AirVan21,项目名称:CPP,代码行数:13,代码来源:List.cpp

示例4: remove

void List::remove(string str) throw (string)
{
    if (size >= 2)
    {
        if (head->getStr() == str)
        {
            ListElement *toDel = head;
            head = head->getNext();
            head->setPrev(NULL);
            toDel->setNext(NULL);
            delete toDel;
            size--;
            return;
        }
        ListElement *temp = head->getNext();
        while(temp->getNext() != NULL)
        {
            if (temp->getStr() == str)
            {
                temp->getNext()->setPrev(temp->getPrev());
                temp->getPrev()->setNext(temp->getNext());
                delete temp;
                size--;
                return;
            }
            temp = temp->getNext();
        }
        if (tail->getStr() == str)
        {
            ListElement *toDel = tail;
            tail = tail->getPrev();
            tail->setNext(NULL);
            size--;
            delete toDel;
            return;
        }
        throw string("No such word!");
    }
    else if (size == 1)
    {
        if (head->getStr() == str)
        {
            delete head;
            size--;
            return;
        }
        throw string("No such word!");
    }
    else
        throw string("List is Empty!");
}
开发者ID:IgorOzernykh,项目名称:HomeTask,代码行数:51,代码来源:List.cpp

示例5: revert

// Before revert List : x, y, z, w
// After revert  List : w, z, y, x 
void List::revert()
{
	// "Write" List in the end
	ListElement *lastModified = mTail;
	ListElement *step;
	// for all elements befor tail
	for (int i = 1; i < mLength; i++) {
		step = mHead;
		// Gets pre lastModified value
		while (step->getNext() != lastModified) {
			step = step->getNext();
		}
		lastModified->setNext(step);
		lastModified = step;
	}
	mHead = mTail;
	mTail = lastModified;
	mTail->setNext(nullptr);
}
开发者ID:AirVan21,项目名称:CPP,代码行数:21,代码来源:List.cpp

示例6: revertNew

void List::revertNew()
{
	ListElement *previous = new ListElement(mHead->getValue());
	// Sets new Tail
	mTail = previous;
	ListElement *step = mHead->getNext();
	while (step) {
		ListElement *clone = new ListElement(step->getValue());
		clone->setNext(previous);
		previous = clone;
		step = step->getNext();
	}
	// Head of reverted List now in previous
	while (mHead) {
		step = mHead;
		mHead = mHead->getNext();
		delete step;
	}
	mHead = previous;
}
开发者ID:AirVan21,项目名称:CPP,代码行数:20,代码来源:List.cpp


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