Technical Interview

Home
Technical Interview
Interview Process
Introduction Questions
Quantitative Problems
Google & Microsoft
Algorithms
Object Oriented
C/C++ Questions
Java Questions
Data Structures
Fundamental Questions
Puzzles
Resume Tips
Added Recently
Links
Contact Us
Submit Question/Answer

 

   
Insert a node in a sorted linked list. Write a C/C++ program.




   


 

Solutions:

 

void sortedInsert(Node * head, Node* newNode)

{

Node *current = head;

           

// traverse the list until you find item bigger the // new node value

     // 

while (current!= NULL && current->data < newNode->data)

{

current = current->next);

}

//

// insert the new node before the big item

//

newNode->next = current->next;

current = newNode;

}