我想完成两个链表以准备考试 这是我到目前为止所拥有的 1 - 反转链表中的元素 2 - 将 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;
}