ashish
BAN USER- 0of 0 votes
Answersinput linked list is : 1->9->3->8->5->7->7
- ashish in India for hyderabad
do you see any pattern in this input ?
odd placed nodes are in increasing order and even placed nodes are in decreasing order.
write a code that gives the the following linkedlist:
output linked list should be 1->3->5->7->7->8->9
?? can it be done inplace ?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Linked Lists - 0of 0 votes
Answersgiven a linked list and two integers M and N. Scan the linked list such that you retain M nodes then delete next N nodes and continue the same till the end of linked list.
- ashish in India for bing| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Linked Lists
input linkedlist= 1->9->3->8->5->7->7
output linked list should be 1->3->5->7->7->8->9
main(){
//head represents the head of the input list as shown above;
list *l=head;
list *evenNode;
list *pre_evenNode;
pre_evenNode=NULL;
while(l!=NULL){
evenNode=l->next;
l->next=l->next->next;
evenNode->next=pre_evenNode;
pre_evenNode=evenNode;
l=l->next;
}
l->next=pre_evenNode;
}
explaination: link all odd nodes one after other and reverse all even nodes while traversing for odd nodes. Finally link tha last odd node with the last even node;
- ashish October 21, 2016