자료구조 :: 양방향 원형 연결리스트

2010/01/01 09:25

이전의 스택과 마찬가지로 연결리스트를 C 언어 라이브러리로 만들어봤습니다.

LinkedListType.h

/*
* =====================================================================================
*
* Filename: LinkedListType.h
*
* Description: LinkedList Library
*
* Version: 1.0
* Created: 2009년 12월 31일 09시 52분 30초
* Revision: none
* Compiler: gcc
*
* Author: Yeonjae Kim (http://hisjournal.net), 6l4ck3y3 (at) gmail.com
* Company: CERT-IS
*
* =====================================================================================
*/

#ifndef _LINKEDLISTTYPE
#define _LINKEDLISTTYPE

/*-----------------------------------------------------------------------------
* List ADT Type
*----------------------------------------------------------------------------*/
// Define element type.
typedef int element;

typedef struct ListNode {
element data;
struct ListNode *prev;
struct ListNode *next;
} ListNode;

typedef struct LinkedListType {
ListNode *node;
int length;
} LinkedListType;

/*-----------------------------------------------------------------------------
* List ADT Function
*----------------------------------------------------------------------------*/
/*
* === FUNCTION ======================================================================
* Name: error
* Description: Exit after displaying error message.
* Parameter: *mesg - error message
* Retuen:
* =====================================================================================
*/
void error (char *mesg);

/*
* === FUNCTION ======================================================================
* Name: init
* Description: Initialize list.
* Parameter: L - list
* Retuen:
* =====================================================================================
*/
void init (LinkedListType *L);

/*
* === FUNCTION ======================================================================
* Name: is_empty
* Description: Return if list is empty.
* Parameter: L - l
* Retuen: If list is empty, this returns 1.
* Otherwise 0.
* =====================================================================================
*/
int is_empty (LinkedListType *L);

/*
* === FUNCTION ======================================================================
* Name: is_in_list
* Description: Return if the item is in list.
* Parameter: L - list
* item - stuff to find
* Retuen: If the item is in list, this returns 1.
* Otherwise 0.
* =====================================================================================
*/
int is_in_list (LinkedListType *L, element item);

/*
* === FUNCTION ======================================================================
* Name: get_length
* Description: Get number of element in list.
* Parameter: L - list
* Return: number 0f element in list
* =====================================================================================
*/
int get_length (LinkedListType *L);

/*
* === FUNCTION ======================================================================
* Name: get_node
* Description: Get the reference of node.
* Parameter: L - list
* Return: reference that is at position
* If it isn't in list, this returns NULL.
* =====================================================================================
*/
ListNode* get_node (LinkedListType *L);

/*
* === FUNCTION ======================================================================
* Name: get_next_node
* Description: Get the reference of next node.
* Parameter: L - list
* Return: reference that is at position
* If it isn't in list, this returns NULL.
* =====================================================================================
*/
ListNode* get_next_node (LinkedListType *L);

/*
* === FUNCTION ======================================================================
* Name: get_prev_node
* Description: Get the reference of prev node.
* Parameter: L - list
* Return: reference that is at position
* If it isn't in list, this returns NULL.
* =====================================================================================
*/
ListNode* get_prev_node (LinkedListType *L);

/*
* === FUNCTION ======================================================================
* Name: insert_node
* Description: Insert a new node at next of the node.
* Parameter: L - list
* : data - data of a new node
* Return:
* =====================================================================================
*/
void insert_node (LinkedListType *L, element data);

/*
* === FUNCTION ======================================================================
* Name: remove_node
* Description: Remove the node.
* Parameter: L - list
* Return:
* =====================================================================================
*/
void remove_node (LinkedListType *L);

/*
* === FUNCTION ======================================================================
* Name: replace
* Description: Change the data of node.
* Parameter: L - list
* : data - new value of data
* Return:
* =====================================================================================
*/
void replace (LinkedListType *L, element data);

#endif


LinkedListType.c

View source...


참고문헌

연결 리스트 :: http://www.winapi.co.kr/clec/cpp2/19-2-1.htm
이중 연결 리스트 :: http://www.winapi.co.kr/clec/cpp2/19-2-2.htm
그 외의 연결 리스트 :: http://www.winapi.co.kr/clec/cpp2/19-2-3.htm
연결 리스트의 활용 :: http://www.winapi.co.kr/clec/cpp2/19-2-4.htm
크리에이티브 커먼즈 라이센스
Creative Commons License

6l4ck3y3 0x07 알고리즘 , ,

Trackback Address:http://hisjournal.net/blog/trackback/301