Study12. 스터디 필수 사항 스터디에한번이라도 빠지면 영영스터디에서 빠져주세요. 과제가 좀 많을 꺼애요 과제 못하면 벌금이 있을꺼애요~ 4. 포인터 왜 쓸까?? 모든 자료형의 포인터는 4byte 메모리에 있는 주소를 가리킨다 주소연산자 ‘&’ 참조연산자 ‘*’ 메모리 할당 malloc 메모리 할당 해제 free 5. 출력 결과는?? charc[100]; double d[100]; char *ptr_c=c; double *ptr_d=d; printf(“%d %d”, sizeof(c), sizeof(ptr_c)); printf(“%d %d”, sizeof(d), sizeof(ptr_d)); 6. 구조체 같거나 다른 자료형을 모아서 새로운 자료형처럼 사용 멤버 변수에 접근 방법 일반변수로 선언했을 경우 "." (직접참조) 포인터로 선언했을 경우 "->" (간접참조) 7. 구조체 사용의 예 typedefstruct{ int age; char name[10]; }node; node v, *ptr_v=(node*)malloc(sizeof(node)); v.age = 100; ptr_v->age = 100; 8. 이런 경우 어떻게 접근하나요? typedefstruct{ int parameter; }item; typedefstruct{ char name[10]; item t1, *t2; }node; node obj1, *obj2=(node*)malloc(sizeof(node)); obj1으로 t1의 parameter에 접근? obj1으로 t2의 parameter에 접근? obj2으로 t1의 parameter에 접근? obj2으로 t2의 parameter에 접근? 9. Linked List 자료를 중간에 삽입, 삭제 시 용이함 첫 Node를 가리키는 ”head” 마지막 Node를 가리키는 “tail” 단순 연결 리스트, 원형 연결 리스트, 이중 연결 리스트 등이 존재 Pointer에 대한 이해가 필수 스터디에서 할 건 단순 연결 리스트 11. 단순 연결 리스트 구현 typedefstruct_node{ int item; struct node *next; }node; typedefstruct{ int item; struct node *next; }node; 12. 단순 연결 리스트 구현 int main(){ node *head = NULL; // … 삽입 루틴 if(head == NULL){ head = (node_ptr)malloc(sizeof(node)); head->next = NULL; head->item = 1; } else insert(head, 2); return 0; } 13. 단순 연결 리스트 구현 void insert(node_ptr head, int item){ node_ptrnewItem = (node_ptr)malloc(sizeof(node)); newItem->item = item; newItem->next = NULL; while(head->next != NULL){ head=head->next; } head->next = newItem; } 15. 단순 연결 리스트에서의 삭제 void del(node_ptr head, int item){ while(head->next != NULL && head->next->item != item){ head=head->next; } if(head->next->item == item){node_ptr temp = head->next; head->next=head->next->next; freetemp;} }