我想完成两个链表,为考试做准备这是我迄今为止所拥有的1-反转链接列表中的元素2-将列表2附加到列表一的末尾
我从课程中的某个人那里得到了反向功能的帮助,并试图对每一步都进行评论,以了解发生了什么,但我很挣扎。如果你也能帮我,那将是一个梦幻般的
在联合收割机功能中,我只是总体上感到困惑我什么时候使用"&"我什么时候用"*"?
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;
}
您只需到达第一个链表的最后一个,在下一个将为null的地方,只需放置下一个链表的开始
我完全理解你为什么颠倒了的列表