crack the code interview 2.1

Write code to remove duplicates from an unsorted linked list.
끊임없이 현재 요소와 앞의 반복이 있으면 현재 요소를 삭제합니다.
struct Node
{
    Node * next;
    int value;
};

void deleteDupNode(Node * head)
{
    if (head == NULL)
        return;
    Node * currentNode = head->next;
    Node * previous = head;
    while (currentNode != NULL)
    {
        Node * start = head;
        while (start != currentNode)
        {
            if (start->value == currentNode->value)
            {
                previous->next = currentNode->next;
                Node * cur = currentNode;
                delete cur;
                break;
            }
        }
        previous = currentNode;
        currentNode = currentNode->next;
    }
}

좋은 웹페이지 즐겨찾기