Home / CSE MCQs / Data Structure MCQs :: Discussion

Discussion :: Data Structure MCQs

  1. Choose the code snippet which inserts a node to the head of the list?
  2. A.

    public void insertHead(int data)


    {


    B.

    public void insertHead(int data)


    {


    C.

    public void insertHead(int data)


    {


    D.

    public void insertHead(int data)


    {


    View Answer

    Workspace

    Answer : Option A

    Explanation :

    If the list is empty make the new node as 'head', otherwise traverse the list to the end and make its 'next' pointer point to the new node, set the new node's next point to the current head and make the new node as the head.


Be The First To Comment