Cisco Systems Interview Question: How would you insert an eleme... | Glassdoor

Interview Question

Software I Intern Interview(Student Candidate) San Jose, CA

How would you insert an element into a singly linked list

 , given that there is also another thread that is iterating over it. (non-blocking)

Interview Answer

2 Answers


The idea is to only break the link in the list once the element to be inserted is pointing at the rest of the list and pointed to by the previous element. If you broke the list first, you could context switch to the iterating thread and stop iterating because the pointer to the next element wouldn't exist.

Interview Candidate on Dec 8, 2012

Apply mutex on the thread

DP on Jan 10, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.