Microsoft Interview Question for Software Engineer / Developers






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

struct node
{
void * data;
struct Node * Prev;
struct Node * Next;
};


struct node * Prev = NULL;
struct node * Next = NULL;
struct node * Cur = Head;

while(Cur != NULL)
{
Next = Cur -> Next;
Cur -> Next = Prev;
Cur -> Prev = Next;
Prev = Cur;
Cur = Next;
}

Head = Prev;

- Rohit Ghatol April 15, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How about this?

struct node
{
void * data;
struct Node * Prev;
struct Node * Next;
};


struct node * Prev = NULL;
struct node * Next = NULL;
struct node * Cur = Head;

while(Cur != NULL)
{
Next = Cur -> Next;
Cur -> Next = Cur -> Prev;
Cur -> Prev = Next;
if(Next != NULL)
Cur = Next;
}

Head = Cur;

- lvv May 20, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Ivv,

Your while will be an infinite loop, since the curr will never be NULL so Rohit's code is more accurate

- TheGreatOne September 08, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

why would you want to reverse a doubly lined list?

- Anonymous October 11, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

No Duh!..
1. Recurse till end of list, and return pointer.

Done!

- Just me! January 26, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Change the name of the pointer "next" to "prev" and vice-versa and return the last node

- Ramu September 09, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct node
{
void * data;
struct Node * Prev;
struct Node * Next;
};
struct node * Cur = Head;
struct node * Temp = NULL;

while(Cur!=NULL){
if(Cur->Prev==NULL){//First Node
Cur->Prev=Cur->Next;
Cur->Next=NULL;
}
Temp=Cur->Next;
Cur->Next=Cur->Prev;
Cur->Prev=Temp;
Cur=Cur->Prev;
}
return Cur;

- CyberPhoenix October 13, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I thought about the code I wrote and its a complete blunder.

So here comes the right code.
struct node
{
void * data;
struct Node * Prev;
struct Node * Next;
};
struct node * Cur = Head;
struct node * Temp = NULL;

while(Cur!=NULL){
Temp=Cur->Next;
Cur->Next=Cur->Prev;
Cur->Prev=Cur->Temp;
Cur=Cur->Prev;//Important
}

return Cur; //Head

- CyberPhoenix October 13, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

//@CyberPhoenix
//my dear i think when u had returened Cur its NULL
//is that of any significance
//well have a look on this!!

struct node
{
void * data;
struct Node * prev;
struct Node * next;
};
struct node * tra = Head;

while(tra){
head= tra->prev;
tra->prev = tra->next;
tra->next = head;
tra = tra->prev;
}
head = head->prev;

- Kapil October 21, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry for using the SMS Language.

- Kapil October 21, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Iterative
void reverdll(node *root){
	node *cur=root;
	node *res=NULL;
	while(cur){
		temp=cur->next;
		cur->next=cur->prev;
		cur->prev=temp;
		cur=temp;
	}
	*root=cur;
}
//Recursion
node* reversedll(node *root){
	if(root==NULL) return NULL;
	else{
		root->prev=reversedll(root->next);
		root->next=root->prev;
		return root;
	}
}

- Vamsi December 05, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Treat this like a singly linked list, and swap the pointers. thats all

/* Ignoring the sentinel cases */
while(root)
{
    SWAP(root->next, root->prev);
    root = root->prev; /* This is next actually */
}

- Bond December 25, 2007 | Flag Reply


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