указатель и справочный вопрос (связанные списки) - PullRequest
0 голосов
/ 24 апреля 2010

У меня есть следующий код

struct Node {
  int accnumber;
  float balance;
  Node *next;
};

Node *A, *B;

int main() {
  A = NULL;  
  B = NULL;
  AddNode(A, 123, 99.87);
  AddNode(B, 789, 52.64);
  etc…
}

void AddNode(Node * & listpointer, int a, float b) {
// add a new node to the FRONT of the list
Node *temp;
  temp = new Node;
  temp->accnumber = a;
  temp->balance = b;
  temp->next = listpointer;
  listpointer = temp;
}

в этом здесь void AddNode(Node * & listpointer, int a, float b) { что означает *& listpointer точно.

1 Ответ

2 голосов
/ 24 апреля 2010

Node * &foo является ссылкой на Node *

Так что когда вы звоните с

AddNode(A, 123, 99.87);

это изменит A.

...