'자료구조&알고리즘'에 해당되는 글 1건
2008/03/20 14:52
[Etc]
#include<stdio.h>
#include<stdlib.h>
/*1.연결리스트의 자료형*/
typedef struct NODE{
int key;
struct NODE *next;
}node;
node *head, *tail;
/*2. 연결리스트의 초기화 */
void init_list(void){
head = (node*)malloc(sizeof(node));
tail = (node*)malloc(sizeof(node));
head->next = tail;
tail->next = tail;
}
/*순차적으로 입력*/
node ordered_list(int k){
node *p;
node *s;
node *n_new;
p = head;
s = p->next;
while(s->key <=k && s!=tail){
p= p->next;
s= p->next;
}
n_new=(node*)malloc(sizeof(node));
n_new->key = k;
n_new->next = s;
p->next = n_new;
return *n_new;
}
void print_list(node *t){
printf("\n");
while(t!=tail){
printf(" %d",t->key);
t=t->next;
}
}
void main(){
init_list();
ordered_list(10);
ordered_list(5);
ordered_list(2);
print_list(head->next);
}
'Etc' 카테고리의 다른 글
| 과제 (0) | 2008/03/20 |
|---|---|
| 트랜스포머 바탕화면 1600x1200 (0) | 2007/08/12 |
Trackback Address :: http://lunics.net/trackback/41



