Contents

조회 수 9838 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

# 간단한 링크드 리스트 자료형 예제

typedef struct { 
    int        index; 
    char    name[10]; 
    char    sex; 
    int      age; 
    char    mail[50]; 
    char    phone[15]; 
    char    address[128]; 
}USER_INFO; 

typedef struct list_node *list_ptr; 
typedef struct list_node { 
    USER_INFO user_info; 
    list_ptr next; 
}LIST_NODE; 
list_ptr first=NULL; 

unsigned long list_cnt=0; 

list_ptr find_list_ptr(int node) 
{ 
    unsigned long i; 
    list_ptr tmp=first; 

    if( node > list_cnt ) 
        node = list_cnt; 

    if( tmp == NULL ) 
        return NULL; 

    for( i=1 ; i<node ; i++ ) 
    { 
        tmp = tmp->next; 
    } 

    return tmp; 
} 

//    add list to end of list 
void add_list() 
{ 
    list_ptr tmp, end; 


    tmp = (list_ptr)malloc( sizeof(LIST_NODE) ); 
    tmp->next = NULL; 

    if( list_cnt == 0 ) 
    { 
        first = tmp; 
    } 
    else 
    { 
        end = find_list_ptr( list_cnt ); 
        end->next = tmp; 
    } 


    list_cnt++; 
} 

void insert_list(unsigned long node) 
{ 
    list_ptr tmp, node_ptr,node_next_ptr ; 

    tmp = (list_ptr)malloc( sizeof(LIST_NODE) ); 

    tmp->next=NULL; 

    if( node >= list_cnt) 
    { 
        add_list(); 
        return; 
    } 

    node_ptr = find_list_ptr(node); 
    node_next_ptr = node_ptr->next; 

    node_ptr->next = tmp; 
    tmp->next = node_next_ptr; 

    list_cnt++; 
} 

void Del_list() 
{ 
    unsigned long i; 
    list_ptr tmp = first; 
    list_ptr tmp_next; 

    for( i=0 ; i<list_cnt; i++ ) 
    { 
        if( tmp->next != NULL) 
        { 
            tmp_next = tmp->next; 
            free(tmp); 
            tmp = tmp_next; 
        } 
        else 
        { 
            if( tmp != NULL ) 
                free(tmp); 
        } 
    } 

    list_cnt = 0; 
}


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
693 Develop [js] 자바스크립트 메뉴얼 사이트.. ㅋㅋ hooni 2013.04.23 7408
692 Develop [c] 단기과정[01/07] 제어문, 피보나치수열 hooni 2003.04.23 7410
691 Develop [php] gd 프로그램.. htm 파일.. ㅋㅋ file hooni 2013.04.23 7412
690 Develop [c] kmp 활용 search file hooni 2013.04.23 7414
689 Develop [jsp] 유효성체크(Client, Server 에서) file hooni 2003.04.23 7416
688 Develop [c] 암호화 알고리즘 DES 구현 ㅋㅋ file hooni 2013.04.23 7433
687 Develop [c] 지폰(gphone) 소스.. 수정(암호화) file hooni 2013.04.23 7434
686 Develop [js] 부모창에서 자식창으로 문자열 전달.. file hooni 2013.04.23 7448
685 Develop [c] 격자 직사각형 넓이 구하기 file hooni 2013.04.23 7457
684 Develop [c] 파일(File) 관련 함수 샘플 코드 file hooni 2003.04.23 7460
683 Develop [js] 이미지 사이즈를 동적으로 조절.. hooni 2013.04.23 7463
682 Develop [c] 간단한 순위 루틴.. (질문에 대한 답변) hooni 2003.04.23 7469
Board Pagination Prev 1 ... 36 37 38 39 40 41 42 43 44 45 ... 98 Next
/ 98