#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
typedef struct node NODE;
struct node
{
char x[6];
NODE *prev;
NODE *next;
};
NODE *head = NULL;
NODE *tail = NULL;
NODE* Find_Node(char *x)
{
NODE *node;
node = (NODE*)malloc(sizeof(NODE));
node = head->next;
while(node != tail)
{
if(strcmp(node->x,x) < 0 )
if(node->next != tail)
{
node = node->next;
continue;
}
else
return node;
if( strcmp(node->x,x) == 0 )
return node;
if( strcmp(node->x,x) > 0 )
/*루트가 처음 head부터 돌기때문에 앞으로 검색은 필요없다..
if(node->prev != head)
{
node = node->prev;
}
else
*/
return node->prev;
}
}
int Insert_Node(char *x)
{
NODE *newnode;
newnode = (NODE*)malloc(sizeof(NODE));
strcpy(newnode->x,x);
if(head == tail)
{
head = (NODE*)malloc(sizeof(NODE));
tail = (NODE*)malloc(sizeof(NODE));
newnode->prev = head;
newnode->next = tail;
head->next = newnode;
tail->prev = newnode;
head->prev = NULL;
tail->next = NULL;
return 0;
}
NODE *temp_node = Find_Node(x);
if(head == temp_node)
{
newnode->prev = head;
newnode->next = head->next;
head->next->prev = newnode;
head->next = newnode;
}
else
{
newnode->prev = temp_node;
newnode->next = temp_node->next;
temp_node->next->prev = newnode;
temp_node->next = newnode;
}
return 0;
}
int Delet_Node(char x)
{
return 0;
}
void Display()
{
NODE *node;
node = (NODE*)malloc(sizeof(NODE));
if( !head )
return;
node = head->next;
while(node != tail)
{
printf("%s\n",node->x);
node = node->next;
}
}
void x_swap(char *a,char *b)
{
char tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
void main()
{
char a='d';
char b='r';
x_swap(&a,&b);
printf("%c\n%c\n",a,b);
Insert_Node("dav");
Insert_Node("cvd");
Insert_Node("ass");
Insert_Node("b'c'");
Insert_Node("c");
Insert_Node("css");
Insert_Node("jlj");
Insert_Node("권오철");
Insert_Node("김건유");
Insert_Node("홍정표");
Insert_Node("이은미");
Insert_Node("권혁신");
Display();
}
'프로그래밍 언어 > 프로그래밍' 카테고리의 다른 글
해시 테이블 (hash table) (0) | 2009.01.18 |
---|---|
트리 (0) | 2009.01.18 |
연결 리스트 (한 글자) (0) | 2009.01.18 |
퀵정렬 (0) | 2009.01.18 |
원형큐 (0) | 2009.01.18 |
댓글