Пример #1
0
void SingleList::sequenceOrderSort(){

	ISingleNode * first = Head, * second = first->getNext();
	int count = 0;

	first->setNext(second->getNext());
	second->setNext(first);
	Head = second;
	count = 3;

	ISingleNode * curr = first, * next = first->getNext();
	second = next;
	//print();
	while (next != NULL)
	{
		for (int i = 1; i < count && second->getNext() != NULL; i++){
			second = second->getNext();
		}

		ISingleNode  * temp = NULL, * temp1 = NULL;
		first = next;
		temp = first;
		next = first->getNext();
		temp1 = next->getNext();
		first->setNext(second->getNext());

		while (first != second){
			next->setNext(first);
			first = next;
			next = temp1;
			if (next)
				temp1 = next->getNext();
		}
		curr->setNext(first);
		curr = temp;
		second = temp->getNext();
		count++;
	}
	//print();
}
Пример #2
0
void SingleList::orderSort2(){

	ISingleNode * first = Head, * second = Head->getNext();

	if (first == NULL || first->getNext() == NULL){
		return;
	}

	Head = second;
	while (true){
		ISingleNode * temp;
		temp = second->getNext();
		second->setNext(first);

		if (temp == NULL || temp->getNext() == NULL){
			first->setNext(temp);
			break;
		}

		first->setNext(temp->getNext());
		first = temp;
		second = first->getNext();
	}
}