Motorola Mobility

  www.motorola.com
Work in HR? Unlock Free Profile

Motorola Mobility Principal Staff Engineer Interview Question

"Write code for inserting a node in a doubly linked list."
Add Tags [?]
Answer

Part of a Principal Staff Engineer Interview Review - one of 193 Motorola Mobility Interview Reviews

Answers & Comments

0
of 0
votes

public void insert(int index, int d){
        Node current = head;
        while(index>0){
            current = current.next;
            index--;
        }
        Node temp = current.next;
        Node inserted = new Node(temp, current, d);
        current.next = inserted;
        if(temp!=null){
            temp.previous = inserted;
        }
    }

- Harsha on Apr 4, 2014

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.