typedef struct node {
int value;
struct node* next;
}node;
int* to_array (node* ll, int size) {
int i = 0;
int* arr = malloc(size*sizeof(int));
while (ll) {
arr[i] = ll->value;
ll = ll->next;
i++;
}
return arr;
}
有人可以請解釋爲什麼結構鏈表到一個數組
int* arr = malloc(size);
會給我們一個數組?我認爲當我們有指針時,我們不能像arr[i] = 5
那樣單獨改變它。
謝謝。我很感謝你的詳細解釋!我現在明白了。 – wiwen
我的榮幸。謝謝*你* :) – FoggyDay