Question
public class Node
{
protected int data;
protected Node prev;
protected Node next;
public Node(int data)
{
this.data = data;
prev = null;
next = null;
}
public Node(int data, Node prev, Node next)
{
this.data = data;
this.prev = prev;
this.next = next;
}
public int getData()
{
return data;
}
public void setData(int data)
{
this.data = data;
}
public Node getPrev()
{
return prev;
}
public void setPrev(Node prev)
{
this.prev = prev;
}
public Node getNext
{
return next;
}
public void setNext(Node next)
{
this.next = next;
}
}
public class DLL
{
protected Node head;
protected Node tail;
int length;
public DLL()
{
head = new Node(Integer.MIN_VALUE,null,null);
tail = new Node(Integer.MIN_VALUE,null,null);
head.setNext(tail);
length = 0;
}
}
a)
public void insertRear(int data)
{
Node node = new Node(data,tail.getPrev(),tail);
node.getPrev().setNext(node);
tail.setPrev(node);
length++;
}
b)
public void insertRear(int data)
{
Node node = new Node(data,tail.getPrev(),tail);
node.getPrev().getPrev().setNext(node);
tail.setPrev(node);
length++;
}
c)
public void insertRear(int data)
{
Node node = new Node(data,tail.getPrev(),tail);
node.getPrev().setNext(tail);
tail.setPrev(node);
length++;
}
d)
public void insertRear(int data)
{
Node node = new Node(data,head,tail);
node.getPrev().setNext(node);
tail.setPrev(node);
length++;
}
a.
a
b.
b
c.
c
d.
d
Posted under Data Structures and Algorithms
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. Given the Node class implementation, select one of the following that correctly inserts a node at the tail of the list.
Similar Questions
Discover Related MCQs
Q. What is a memory efficient double linked list?
View solution
Q. How do you calculate the pointer difference in a memory efficient double linked list?
View solution
Q. What is the time complexity of inserting a node in a doubly linked list?
View solution
Q. Consider the 2-level skip list. How to access 38?
View solution
Q. Consider an implementation of unsorted singly linked list. Suppose it has its representation with a head pointer only.
Given the representation, which of the following operation can be implemented in O(1) time?
i) Insertion at the front of the linked list
ii) Insertion at the end of the linked list
iii) Deletion of the front node of the linked list
iv) Deletion of the last node of the linked list
View solution
Q. In linked list each node contain minimum of two fields. One field is data field to store the data second field is?
View solution
Q. What would be the asymptotic time complexity to add an element in the linked list?
View solution
Q. What would be the asymptotic time complexity to find an element in the linked list?
View solution
Q. What would be the asymptotic time complexity to insert an element at the second position in the linked list?
View solution
Q. The concatenation of two list can performed in O(1) time. Which of the following variation of linked list can be used?
View solution
Q. Linked lists are not suitable to for the implementation of?
View solution
Q. Linked list is considered as an example of ___________ type of memory allocation.
View solution
Q. In Linked List implementation, a node carries information regarding
View solution
Q. Linked list data structure offers considerable saving in
View solution
Q. Which of the following is not a disadvantage to the usage of array?
View solution
Q. What is the time complexity of inserting at the end in dynamic arrays?
View solution
Q. What is the time complexity to count the number of elements in the linked list?
View solution
Q. What is the space complexity for deleting a linked list?
View solution
Q. Which of these is an application of linked lists?
View solution
Q. What differentiates a circular linked list from a normal linked list?
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!