글
#include "LINKEDLIST.H" void node_print1(node * head) { while(0!=head) { printf("%c->", head->data); head=head->next; } printf("\n"); } void node_print(node * head) { for(head; 0!=head; head=head->next) { printf("%c->", head->data); } printf("\n"); } void node_free(node * head) { node * temp; for(temp=head; 0!=head; temp=temp->next) { head = head->next; free(temp); printf("malloc was deleted \n"); } } node* node_insert(node * head, char cdata) { node * stpnew; node * stpfront; node * stprear; stpfront = head; stprear = head; stpnew = malloc(sizeof(node)); stpnew->data = cdata; stpnew->next = 0; while(0!=stprear) //serching { if(stprear->data > stpnew->data) // 삽입할위치판단 { break; } stpfront = stprear; stprear = stprear->next; } if(head!=stprear) { stpnew->next =stprear; stpfront->next =stpnew; } else { stpnew->next = head; head = stpnew; } return head; } node* node_del(node * head, char cdata) { node * stpfront; node * stprear; stpfront = head; stprear = head; while(0!=stprear) //serching { if(stprear->data == cdata) // 삽입할위치판단 { break; } stpfront = stprear; stprear = stprear->next; } if( 0== stprear) { return head; }//없을때 else if(head !=stprear) { stpfront->next= stprear->next; }//중간 삭제 else { head = head->next; }//앞삭제 free(stprear); return head; } |
'C언어' 카테고리의 다른 글
20140428 USART통신 (0) | 2014.04.28 |
---|---|
20140425 파일열고닫기 (0) | 2014.04.25 |
20140421 링크드리스트 (0) | 2014.04.21 |
20140417 링크드리스트 (0) | 2014.04.17 |
20140406 링크드리스트 분할컴파일 (0) | 2014.04.16 |
RECENT COMMENT