#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 toFind,int data){
    node *tmp,*toInsert ;
    int flag = 1;
    if(*start==NULL){ //업을때는 검색없이 삽입
        *start = get_node();
        (*start)->data = data;
        return;
    }
    tmp = *start;
    while(1){
        if(toFind == tmp->data){
            toInsert = get_node();
            toInsert->link = tmp->link;
            tmp->link = toInsert;
            toInsert->data = data;

            return;
        }
        if(tmp->link ==NULL)break;
        tmp = tmp->link;
       
    }
   
    toInsert = get_node();
    toInsert->data = data;
    tmp->link = toInsert;   
   
}
void deletex(node **start,int toFind){
    node *tmp,*toInsert,*trail ;
    int flag = 1;
    if(toFind == (*start)->data  ){
        tmp = *start;
        *start = (*start)->link ;
        free(tmp);
        return;
    }
    tmp = *start;   
    while(1){
        if(toFind == tmp->data){

            trail->link = tmp->link;
            free(tmp);
            return;
        }
        if(tmp->link ==NULL)break;
        trail = tmp; //<------
        tmp = tmp->link;
        
    }
   
   
}
int main(int* argc,char* argv[]){
    node *start=NULL;
    insert(&start,343, 3);  //첫값
    insert(&start,3  , 34); //3뒤에 붙는 값.
    insert(&start,111, 11); //못찾아서 맨뒤에 붙는 값.
    deletex(&start,3);
    deletex(&start,34);

   
    pl(start);
}