목록Linked List (5)
웅재의 코딩세상
sortList함수 FunctionName sortList - 노드 정렬 (오름차순) Parameters lp - 리스트 관리 구조체의 주소 Returns 없다. void shortList(List *lp){ Node *curp; Node *nextp; int temp; if(lp==NULL) return; curp = lp -> head -> next; while(curp->next != lp -> tail){ nextp = curp -> next; while(nextp != lp -> tail){ if(curp -> data > nextp -> data){ temp = curp -> data; curp -> data = nextp -> data; nextp -> data = temp; } nextp ..
searchNode 함수 FunctionName searchNode - data와 일치하는 첫 번째 node 검색 Parameters lp - 리스트 관리 구조체의 주소 data - 검색할 데이터 Returens 성공 - 검색된 노드의 주소 실패 - NULL pointer Node * searchNode(List *lp, int data){ Node *curp; if(lp == NULL) return NULL; // lp 포인터 NULL check curp = lp -> head -> next; // data가 있는 첫 노드를 curp로 가리키게 한다. while (curp != lp -> tail){ // 리스트의 마지막 데이터 노드까지 curp를 옮기면서 검색하기 if(curp->data == dat..
addFirst 함수 Function name addFirst - head node 뒤에 node 추가 ( 역순 저장 ) Parameters lp - 리스트 관리 구조체의 주소 data - 추가할 데이터 Return 성공 - TRUE 실패 - FALSE BOOL addFirst(List *lp, int data){ Node *newp; if(lp == NULL) return FALSE; //lp포인터 NULL check newp = (Node *)malloc(sizeof(Node)); // 새 node 생성 if(newp != NULL){ newp -> data = data; // 새 node에 데이터 저장 newp -> next = lp -> head -> next; // 새 node의 next 연결 ..
singly linked list 구현에 사용되는 데이터 형 enum bool { false, true }; typedef struct _node Node; // 구조체 노드 형명 재지정 struct _node{ //노드 구조체 int data; // 데이터 영역 : int 형 데이터 저장 Node *next; // 포인터 영역 } typedef struct _list{ // linked list 관리 구조체 Node *head; // head pointer ( head node 가리킴 ) Node *tail; // tail pointer ( tail node 가리킴 ) int size; // linked list의 크기 - 실제 data node의 개수 }List; singly linked list 기..

데이터를 저장한 단위 메모리가 서로 연결되어 있는 자료구조이다. 단일 연결 리스트 ( singlt linked list ) : 리스트가 각 노드에 다른 노드를 가리키는 포인터가 하나씩만 있는 연결 리스트 linked list VS array 구현방식 Array : 고정 크기 메모리를 사용한다. Linked list : Node(구조체) 연결 방식을 사용한다. 메모리 효용성 Array : 낮음 Linked list : 높음 삽입 및 삭제 속도 Array : 느림 ( 원소 이동 필요 ) Linked list : 빠름 ( 원소 이동 필요 없음 ) 원소 접근 속도 Array : 빠름 Linked list : 느림 구현 복잡도 Array : 간단 Linked list : 복잡 Singly linked list 관..