Which Of The Following Performs Deletion Of The Last Element In #75
Which of the following performs deletion of the last element in the list? Given below is the Node class.</p> <pre><code class="language-java">class Node { protected Node next; protected Object ele; Node(Object e,Node n) { ele = e; next = n; } public void setNext(Node n) { next = n; } public void setEle(Object e) { ele = e; } public Node getNext() { return next; } public Object getEle() { return ele; } } class SLL { Node head; int size; SLL() { size = 0; } }</code></pre>
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 - Singly Linked Lists - Quiz No.1.
Which of the following performs deletion of the last element in the list? Given below is the Node class.
class Node { protected Node next; protected Object ele; Node(Object e,Node n) { ele = e; next = n; } public void setNext(Node n) { next = n; } public void setEle(Object e) { ele = e; } public Node getNext() { return next; } public Object getEle() { return ele; } } class SLL { Node head; int size; SLL() { size = 0; } }
public Node removeLast() { if(size == 0) return null; Node cur; Node temp; cur = head; while(cur.getNext() != null) { temp = cur; cur = cur.getNext(); } temp.setNext(null); size--; return cur; }
public void removeLast() { if(size == 0) return null; Node cur; Node temp; cur = head; while(cur != null) { temp = cur; cur = cur.getNext(); } temp.setNext(null); return cur; }
public void removeLast() { if(size == 0) return null; Node cur; Node temp; cur = head; while(cur != null) { cur = cur.getNext(); temp = cur; } temp.setNext(null); return cur; }
public void removeLast() { if(size == 0) return null; Node cur; Node temp; cur = head; while(cur.getNext() != null) { cur = cur.getNext(); temp = cur; } temp.setNext(null); return cur; }
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