void BubbleSort Figure head Figure currentNode nextNode temp while tru

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
void BubbleSort(Figure* head){
Figure *currentNode, *nextNode, *temp;
while(true){
bool flag = true;
for (currentNode = head, nextNode = currentNode->nextNode; nextNode->nextNode != head; currentNode = currentNode->nextNode, nextNode = currentNode->nextNode) {
if ([nextNode getSquare] > [nextNode->nextNode getSquare]) { // если следующее меньше предыдущего
currentNode->nextNode = nextNode->nextNode;
nextNode->nextNode = (nextNode->nextNode)->nextNode;
(nextNode->nextNode)->nextNode = nextNode;
// currentNode->nextNode = nextNode->nextNode;
NSLog(@"%f - %f\n", [currentNode->nextNode getSquare], [nextNode->nextNode getSquare]);
}
else{
break;
}
flag = false; // на данном шаге сортировку выполнили, переходим на следующий
}
if(flag) break;
}
// Figure *currentNode, *nextNode, *temp;
// for (currentNode = head->nextNode, nextNode = currentNode->nextNode; (currentNode->nextNode)->nextNode != head; currentNode = currentNode->nextNode, nextNode = currentNode) {
// for (Figure *currentNode1 = head->nextNode, *nextNode1 = currentNode1->nextNode; (currentNode1->nextNode)->nextNode != head; currentNode1 = currentNode1->nextNode, nextNode1 = currentNode1) {
// if ([nextNode getSquare] > [nextNode1 getSquare]) {
// temp = nextNode1;
// currentNode->nextNode = nextNode1;
// nextNode1->nextNode = nextNode->nextNode;
// currentNode1->nextNode = nextNode;
// nextNode->nextNode = temp->nextNode;
// break;
// }
// }
// }
}