#include <stdio.h>
#include <malloc.h>
typedef struct _node {
int name;
struct _node *link;
} node;
node *head, *tail;
void init();
void odered_insert(int name);
void nexted_insert(int k);
void print_node();
node* find(int name);
void del(int name);
void modify(int std_name,int mod_name);
void main(){
node *temp;
init();
odered_insert(1);
odered_insert(2);
odered_insert(3);
odered_insert(4);
odered_insert(5);
modify(5,7);
nexted_insert(3,0);
del(4);
print_node();
}
void init(){
head = (node*)malloc(sizeof(node));
tail = (node*)malloc(sizeof(node));
head->link = tail;
tail->link = 0;
}
void odered_insert(int name){
node *temp;
node *h;
temp = (node*)malloc(sizeof(node));
h = head;
while(h->link != tail){
h = h->link;
}
temp->name = name;
h->link = temp;
temp->link = tail;
}
void nexted_insert(int std_name,int nxt_name){
node *std_temp;
node *nxt_temp;
std_temp = find(std_name);
nxt_temp = (node*)malloc(sizeof(node));
nxt_temp->link = std_temp->link;
nxt_temp->name = nxt_name;
std_temp->link = nxt_temp;
}
void print_node(){
node *temp;
temp = head->link;
while(temp->link != 0){
printf("%d\n",temp->name);
temp = temp->link;
}
}
node* find(int name){
node *temp;
temp = head->link;
while(temp->name != name){
temp = temp->link;
}
return temp;
}
void del(int name){
node *pre_temp;
node *del_temp;
del_temp = find(name);
pre_temp = head->link;
while(pre_temp->link != del_temp){
pre_temp = pre_temp->link;
}
pre_temp->link = del_temp->link;
free(del_temp);
}
void modify(int std_name,int mod_name){
node *temp;
temp = find(std_name);
temp->name = mod_name;
}
'IT > Algorithm' 카테고리의 다른 글
Algorithm: 큐(Queue) (0) | 2012.11.20 |
---|---|
Algorithm: 이중 연결 리스트(Doubly linked list) (0) | 2012.11.13 |
Algorithm: 러시아 농부 곱셈법(a la russe) (0) | 2012.10.30 |
Algorithm: 요세푸스의 문제(Josephus Problem) (0) | 2012.10.19 |
Algorithm: 에라토스테네스의 체(Eratosthenes' Sieve) (0) | 2012.10.16 |