Remove duplicates from unsorted linked list Remove duplicate elements from linked list.

#include&lt;iostream&gt;
using namespace std;

class LinkedList{
private:
    int data;
    LinkedList *next;
public:
    void insert(LinkedList **start, int data){
        LinkedList *p = new LinkedList;
        if (*start == NULL){
            p-&gt;data = data;
            p-&gt;next = NULL;
            *start = p;
        }
        else{
            LinkedList *temp = *start;
            while (temp-&gt;next != NULL){
                temp = temp-&gt;next;
            }
            temp-&gt;next = p;
            p-&gt;data = data;
            p-&gt;next = NULL;
        }
    }
    void removeDuplicates(LinkedList **start){//This function removes the duplicates using the standard runner method taking 2 pointers
        LinkedList *temp = *start;
        LinkedList *temp1 = (*start);
        while (temp != NULL){
                while (temp1-&gt;next!=NULL){
                    if (temp-&gt;data == temp1-&gt;next-&gt;data){
                        LinkedList *p;
                        p = temp1-&gt;next;
                        temp1-&gt;next = temp1-&gt;next-&gt;next;
                        delete(p);
                    }
                    else{
                        temp1 = temp1-&gt;next;
                    }

                }

            temp = temp-&gt;next;
            temp1 = temp;
        }
    }

    void traverse(LinkedList **start){
        LinkedList *temp = *start;
        while (temp != NULL){
            cout &lt;&lt; temp-&gt;data;
            temp = temp-&gt;next;
        }
    }
};

int main(){
    LinkedList *start = NULL;
    LinkedList p1;
    p1.insert(&amp;start, 9);
    p1.insert(&amp;start, 8);
    p1.insert(&amp;start, 7);
    p1.insert(&amp;start, 9);
    p1.insert(&amp;start, 8);
    p1.traverse(&amp;start);
    p1.removeDuplicates(&amp;start);
    cout &lt;&lt; "\n";
    p1.traverse(&amp;start);
    getchar();
    return 0;
}


This takes \$O(N^2)\$ time. Can we do the same in \$O(N)\$ without the use of hash table? Or if mandatory how can we implement it in C++?

How is the overall code quality of the above code? Is there any scope of improvement?
I see a number of things that may help you improve your code.

Make sure you have all required #includes

The code uses getchar but doesn't #include &lt;cstdio&gt;.  Also, carefully consider which #includes are part of the interface (and belong in the .h file) and which are part of the implementation.

Avoid raw pointers

In modern C++, we tend not to use raw pointers very often.  In this case, It would probably be better to have two different classes, one would be a LinkedList class and the other would be a Node class.  That way, instead of starting with a pointer, you can start with an object.

Use nullptr rather than NULL

Modern C++ uses nullptr rather than NULL.  See this answer for why and how it's useful.  

Match new with delete

If you allocate memory using new, you must also free it using delete or your program will leak memory.  Since you use new in insert(), you should use delete in the LinkedList destructor which you have not yet written.

Don't abuse using namespace std

Putting using namespace std within your program is generally a bad habit that you'd do well to avoid.  

Use more descriptive names

The code's traverse function actually prints the nodes.  For that reason it should probably be named something like print().  Even better would be to have such a function take a std::ostream&amp; argument so it would be possible to print to something other than std::cout.

Omit return 0

If your program completes successfully, the return 0 at the end of main() will be generated automatically, so it's not needed in C++ programs.