Which Of The Following Piece Of Code Removes The Node From A #86
Which of the following piece of code removes the node from a given position?
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 - Doubly Linked Lists - Quiz No.1.
Which of the following piece of code removes the node from a given position?
public void remove(int pos) { if(pos<0 || pos>=size) { System.out.println("Invalid position"); return; } else { if(head == null) return; if(pos == 0) { head = head.getNext(); if(head == null) tail = null; } else { Node temp = head; for(int i=1; i<position; i++) temp = temp.getNext(); } temp.getNext().setPrev(temp.getPrev()); temp.getPrev().setNext(temp.getNext()); } size--; }
public void remove(int pos) { if(pos<0 || pos>=size) { System.out.println("Invalid position"); return; } else { if(head == null) return; if(pos == 0) { head = head.getNext(); if(head == null) tail = null; } else { Node temp = head; for(int i=1; i<position; i++) temp = temp.getNext(); } temp.getNext().setPrev(temp.getNext()); temp.getPrev().setNext(temp.getPrev()); } size--; }
public void remove(int pos) { if(pos<0 || pos>=size) { System.out.println("Invalid position"); return; } else { if(head == null) return; if(pos == 0) { head = head.getNext(); if(head == null) tail = null; } else { Node temp = head; for(int i=1; i<position; i++) temp = temp.getNext().getNext(); } temp.getNext().setPrev(temp.getPrev()); temp.getPrev().setNext(temp.getNext()); } size--; }
public void remove(int pos) { if(pos<0 || pos>=size) { System.out.println("Invalid position"); return; } else { if(head == null) return; if(pos == 0) { head = head.getNext(); if(head == null) tail = null; } else { Node temp = head; for(int i=1; i<position; i++) temp = temp.getNext().getNext(); } temp.getNext().setPrev(temp.getNext()); temp.getPrev().setNext(temp.getPrev()); } 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