동적할당에 대하여..
이슬비
2023.04.01
일단은 소스가요...
#includestdio.h#includestdlib.hstruct llist{ int x; llist *next;};int main(){ llist *head,*temp,*bef; temp=new llist; temp-x=1;temp-next=NULL; head=temp; temp=new llist;temp-x=2;temp-next=NULL;head-next=temp;temp=head;while(temp!=NULL){ printf(%d\n,temp-x);bef=temp; temp=temp-next; free(bef);} return 0;}이건데요 .. 동적 할당이 이해가 안가네요 좀가르쳐주세요 ..
-
다크
네.감사합니당~^^
-
영미
아...c게시판에 c스타일로 되어잇네요 ㅋ
new로 동적할당해준건 delete해줘야 합니다
c에서 ~alloc 와 free랑 같은맥락입니다 -
매화
그런데 new로 동적할당 한 건 좋은데...
delete를 써야 하는것 아닌가요..? -
목향
음...
new문이 있는데 못보셨나보네요. ;ㅁ; -
머슴밥
링크드 리스트네요. 그런데 여기에 동적할당은 안보입니다;
링크드리스트는 노드를 하나씩 붙여가는 자료구조입니다. 그 노드를 붙이기 위해 동적할당으로 노드를 만듭니다.