<div>#include <stdio.h></div> <div>#include <stdlib.h></div> <div><br></div> <div>typedef struct node{</div> <div><span style="white-space:pre;"> </span>int data;</div> <div><span style="white-space:pre;"> </span>struct node *link;</div> <div>} ListNode;</div> <div><br></div> <div>ListNode *head = NULL, *tail = NULL;</div> <div>void printNode(ListNode *p){</div> <div><span style="white-space:pre;"> </span>if(p==NULL){printf("NULL\n"); return;}</div> <div><span style="white-space:pre;"> </span>else{</div> <div><span style="white-space:pre;"> </span>printf("%d->",p->data);</div> <div><span style="white-space:pre;"> </span>printf("a\n");</div> <div><span style="white-space:pre;"> </span>printNode(p->link);</div> <div><span style="white-space:pre;"> </span>}</div> <div>}</div> <div>void appendNode(int item){</div> <div><span style="white-space:pre;"> </span>ListNode *tmp;</div> <div><span style="white-space:pre;"> </span>tmp=(ListNode *)malloc(sizeof(ListNode));</div> <div><span style="white-space:pre;"> </span>tmp->data=item;</div> <div><span style="white-space:pre;"> </span>tmp->link=NULL;</div> <div><span style="white-space:pre;"> </span>if(!head){</div> <div><span style="white-space:pre;"> </span>head=tail=tmp;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>else{</div> <div><span style="white-space:pre;"> </span>tail->link=tmp->link;</div> <div><span style="white-space:pre;"> </span>tail=tmp;</div> <div><span style="white-space:pre;"> </span>}</div> <div>}</div> <div>int main(int argc, const char * argv[]){</div> <div><span style="white-space:pre;"> </span>for(int i=1; i<10; ++i){</div> <div><span style="white-space:pre;"> </span>appendNode(i);</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>printNode(head);</div> <div><span style="white-space:pre;"> </span>return 0;</div> <div>}</div> <div>결과 값이 1->2->3 .... ->9-> 이렇게 나와야되는데 자꾸 1에서 끝나네요 틀린곳좀 찾아주세요!</div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.