Views 9838 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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

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
No. Category Subject Author Date Views
837 Develop [c] 소켓 프로그래밍 요약.. hooni 2003.04.23 6964
836 Develop [c] 소켓의 세가지 동작모드 hooni 2003.04.23 6904
835 Develop [c] 소켓주소 구조체에 대해.. hooni 2003.04.23 6724
834 Develop [c] 숫자 맞추는 게임.. file hooni 2013.04.23 6929
833 Develop [c] 숫자(int, Number)를 hex코드로 변환하는 소스 file hooni 2013.04.23 8122
832 Develop [c] 스택/힙 오버플로우 테스트(overflow) file hooni 2003.04.23 7324
831 Develop [c] 스토리지 클래스(변수) hooni 2003.04.23 8197
830 Develop [c] 시간 계산 하는 프로그램 소스코드 file hooni 2003.04.23 6745
829 Develop [c] 시간 관련 함수 설명과 예제.. file hooni 2003.04.23 11523
828 Develop [c] 시간(요일,날짜 포함) 출력하는 프로그램 초간단 코드 hooni 2013.04.23 7392
827 Develop [c] 시스템 보안 과제.. 시간(amc time) 변경 file hooni 2013.04.23 7193
826 Develop [c] 시스템공학 레포트 (pass1, pass2) file hooni 2003.04.23 7181
825 Develop [c] 시어핀스키 가스킷..(p.582, A.2 - 두번째) hooni 2003.04.23 7474
824 Develop [c] 신기한 atoi함수(www.game79.net) hooni 2003.04.23 7273
823 Develop [c] 심심해서.. fseek() 예제.. file hooni 2003.04.23 7227
822 Develop [c] 싱글, 더블 링크리스트(linked list)로 만든 예제.. file hooni 2003.04.23 6737
Board Pagination Prev 1 ... 20 21 22 23 24 ... 74 Next
/ 74