연결 리스트(Linked List)

■ 연결 리스트(Linked List)

[ 삭제 함수 ] ---> 연결 리스트의 노드 삭제

void delete(int x, LIST L)
{
    position p, tmp_cell;
    p = L;
    while((p->next != NULL) && (p->element != x))
            p = p->next; /* Find pointer of previous element */
    if(p->next != NULL)
    {
            tmp_cell = p->next;                  /* ① */
            p->next = tmp_cell->next;        /* ② */
            free( tmp_cell);                        /* ③ */
    }
}