所以,我有一些代码,类似于以下,将结构添加到结构列表:
void barPush(BarList * list,Bar * bar)
{
// if there is no move to add, then we are done
if (bar == NULL) return;//EMPTY_LIST;
// allocate space for the new node
BarList * newNode = malloc(sizeof(BarList));
// assign the right values
newNode->val = bar;
newNode->nextBar = list;
// and set list to be equal to the new head of the list
list = newNode; // This line works, but list only changes inside of this function
}
Run Code Online (Sandbox Code Playgroud)
这些结构定义如下:
typedef …Run Code Online (Sandbox Code Playgroud)