Choose The Code Snippet Which Inserts A Node To The Head Of The #98
Choose the code snippet which inserts a node to the head of the list?
This multiple choice question (MCQ) is related to the book/course gs gs121 Data Structures and Algorithms. It can also be found in gs gs121 Abstract Data Types - Circular Linked Lists - Quiz No.1.
Choose the code snippet which inserts a node to the head of the list?
public void insertHead(int data) { Node temp = new Node(data); Node cur = head; while(cur.getNext() != head) cur = cur.getNext() if(head == null) { head = temp; head.setNext(head); } else { temp.setNext(head); head = temp; cur.setNext(temp); } size++; }
public void insertHead(int data) { Node temp = new Node(data); while(cur != head) cur = cur.getNext() if(head == null) { head = temp; head.setNext(head); } else { temp.setNext(head.getNext()); cur.setNext(temp); } size++; }
public void insertHead(int data) { Node temp = new Node(data); if(head == null) { head = temp; head.setNext(head); } else { temp.setNext(head.getNext()); head = temp; } size++; }
public void insertHead(int data) { Node temp = new Node(data); if(head == null) { head = temp; head.setNext(head.getNext()); } else { temp.setNext(head.getNext()); head = temp; } size++; }
Similar question(s) are as followings:
Online Quizzes of gs121 Data Structures and Algorithms
Binary Trees - Binary Search Tree - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Binary Search Tree - Quiz No.2
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Preorder Traversal - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes