#include<stdio.h>
#include<stdlib.h>
#define MAX 300000
#define DEBUG 0
typedef struct{
int data;
struct node * link;
}node;
node * get_node(){
node *tmp =(node *)malloc(sizeof(node));
tmp->data = 0;
tmp->link = NULL;
return tmp;
}
void pl(node *start){
node *tmp;
printf("%d n",start->data);
if(start->link==NULL)return ;
tmp = start->link;
while(1){
printf("%d n",tmp->data);
if(tmp->link == NULL)break;
tmp = tmp->link;
}
}
void insert(node **start,int data){
node *tmp,*toInsert,*old ;
int flag = 0;
if(*start==NULL){ //업을때는 검색없이 삽입
*start = get_node();
(*start)->data = data;
return;
}
tmp = *start;
while(1){
old=tmp->link;
if(old ==NULL){
flag=1;
}else if(data < old->data ){
flag=1;
}
if(flag){
toInsert = get_node();
toInsert->link = tmp->link;
tmp->link = toInsert;
toInsert->data = data;
return;
}
if(tmp->link ==NULL)break;
tmp = tmp->link;
}
}
int main(int* argc,char* argv[]){
node *start=NULL;
insert(&start, 3);
insert(&start, 34);
insert(&start, 11);
insert(&start, 4);
insert(&start, 5);
insert(&start, 22);
pl(start);
}


