0

試験の準備として 2 つのリンクされたリストを完成させたいと思っています。これまでのところ、1 - リンクされたリストの要素を反転させます。2 - リスト 1 の最後に list2 を追加します。

コースの誰かからリバース機能の助けを借りて、何が起こっているのかを理解するために各ステップをコメントアウトしようとしましたが、苦労しています. あなたもそれで私を助けることができれば、それは素晴らしいことです

結合関数では、全体的に混乱していますいつ「&」を使用し、いつ「*」を使用しますか?

typedef struct node *list;

typedef struct node {
    int   value;
    list  whateverNextIsCalled;
} node;

// Reverse list
list reverse (list inputList){
    list outputList = NULL;

    while (inputList != NULL) {

       /*
        nodePtr points to the first element in the inputList
        */
        node *nodePtr = inputList;

       /* 
        Make the head pointer of inputList point to the next element
        */
        inputList = inputList->whateverNextIsCalled;

       /*
        ???? help point 1
        */
        nodePtr->whateverNextIsCalled = outputList;

       /*
        ???? help point 2
        */
        outputList = nodePtr;
    }
    return outputList;
}

// Add one list to the end of another
void combine (list list1, list list2){

   /*
    Point to the first value of list1 
    */
    node *current = list1;

   /*
    Find the last node of list1
    */
    while(current->whateverNextIsCalled != NULL) {
        current = current->whateverNextIsCalled;
    }
    //connect the last node of toList and the first node of fromList
    current->whateverNextIsCalled = &list2;

    list1 = current;
}    
4

1 に答える 1