VMWare Inc Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
1
of 1 vote

delete(Node head, int value){
    if(!head) return;
    node = head;
    prev = null;
    while(node != null){
        next = node.next
        if(node.value == value){
            if(prev == null){
                /* head node */
                free(node)
                return next; // incase head is only node, null will be returned
            }
            prev.next = node.next // in case last node, prev.next will point to null
            free(node)
            return head
        }
        prev = node
        node = next
    }
}

- Anonymous November 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* Delete node in linked list */
void Delete(struct node **begin)
{
struct node *temp,*previous;
int node_number,count;

count = 1;

printf("\n Enter Node Number to be deleted : ");
scanf("%d",&node_number);

if(node_number <= 0)
{
printf("\n\n Node does not exist!! List begins with 1.");
return;
}

temp = *begin;

while(temp != NULL)
{
if(count == node_number)
{
if(temp == *begin) /*if want to delete First Node*/
{
*begin = temp->next;
free(temp);
return;
}
else if(temp->next == NULL) /*if want to delete Last Node*/
{
previous->next = NULL;
free(temp);
return;
}
else
{
previous->next = temp->next;
free(temp);
return;
}
}
else
{
previous = temp;
temp = temp->next;
count ++;
}
}
printf("\n\n Link List has only %d nodes",count-1);
}

- Abhishek January 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Abhishek, the question gives you the data of the node, not the node number.

- Anonymous January 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

More simple

Node delete(Node head, int value)
{
	if(head == null)
		return;

	if(head->value == value){
		return head->next;
	}

	Node next = head->next;
	while(next){
		if(next->value == value){
			next->next = next->next->next;
			break;
		}
	}

	return head;
}

- gevorgk June 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hi gevorqk,
this will not work, since in line:
next->next = next->next->next;
you are not deleting this node,
you need to save :
Node curr=head;
Node next=head->next;
while(next){
if(next->value == value){
curr->next = next->next;
break;
}
curr = next;
next = next->next;
}

- Anonimous April 15, 2014 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More