Home Forums US Life c++ 아래 짧은 링크드 리스트 코드중 2가지 궁금한것 c++ 아래 짧은 링크드 리스트 코드중 2가지 궁금한것 Name * Password * Email 아래 처럼 while 루프를 for 루프로 고쳐서 다시 쓰면, temp 와 head의 관계에 대해서 쪼끔 이해가 편해지는듯... 😜 ` void insertAfter(node* head, int key, int val) { node* n = new node(val); if (key == head->data) { n->next = head->next; head->next = n; return; } node* temp ; for( temp = head; temp->data != key; temp = temp->next) // 템프는 헤드로 초기화시켜서 링크드리스트를 아이터레이터처럼 트래버스 시켜줌. 헤드와 같은게 아니라. if (temp == NULL) // key가 없는 경우 return; n->next = temp->next; temp->next = n; } ` I agree to the terms of service Comment