is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
I found another error in this code:
- azizahmad45 September 05, 2013The line "if ( current == obj )" is not correct. You are comparing node address not the value. BTW you did great job. This code will work for all datatypes. All you need is to use templates.
The corrected code and results are attached:
// Search if the object is already in the list of unique characters that's been searched
bool LinkedList::isUniqueSearchSubList(Node *tail, Node *obj)
{
Node *current = head;
while ( current != tail->next )
{
// if ( current == obj ) // we found a duplicate!
// you are comparing nodes not the actual value, the code
// should be changed to
if ( current->data == obj->data ) // we found a duplicate!
return false;
current = current->next;
}
return true;
}
void LinkedList::RemoveDuplicate()
{
if ( head == NULL || head->next == NULL ) return; // check empty and 1 element list
Node *prev = head;
Node *current = head->next;
Node *tail = head; // the end of the list of unique characters we gone through
while ( current != NULL ) {
// check if the current node is already in the list of unique objects ( head to tail )
if ( isUniqueSearchSubList(tail, current ) == true )
{
tail = tail->next; // unique so include it in the list by incrementing tail
prev = current; // added this line
current = current->next;
} else {
// delete the current one
prev->next = current->next;
current = current->next;
}
}
}
Result:
Before: 1 3 7 5 8 8 8 2 3 4 5 5 6 7 7 7 9 8 9 3 2 10 1
After: 1 3 7 5 8 2 4 6 9 10