0

I am trying to understand MarchingCube algorithm: My previous question was this. Now I am stuck in one function where the node ( which holds each grid of whole cube in linked list kind of structure) is inserted. I can understand the first few line of the code but, when I look at the code I find some part of the code redundant.

NODE *Insert(NODE *listset, NODE *tmpNode) {
1    NODE *temp;
2
3    if(listset == NULL) return tmpNode;
4    else {
5        tmpNode->next = listset->next;
6        listset->next = tmpNode;
7        return listset;
8    }
9    temp = listset;
10    if(temp->next == NULL) {
11       if(temp->depth > tmpNode->depth) temp->next = tmpNode;
12            else {
13                tmpNode->next = temp;
14                listset = tmpNode;
15            }
16         return listset;
17    }
18    while(temp->next != NULL) {
19        if(temp->next->depth > tmpNode->depth) temp = temp->next;
20        else {
21            tmpNode->next = temp->next;
22            temp->next = tmpNode;
23            return listset;
24        }
25     }
26     temp->next = tmpNode;
27     return listset;

}

In this function from 1 to 8 perfectly makes sense ( its just inserting new node to its end). How could code ever reach after that point (I mean code from 9-27) ?? Is it even necessary??

Can anyone please explain what is going in the part 9-27.

4

0 回答 0