- Computer Science Engineering (CSE)
- Data Structure (DS)
- How do you insert a node at the beginnin...

Q. |
## How do you insert a node at the beginning of the list? |

A. | public class insertfront(int data) { node node = new node(data, head, head.getnext()); node.getnext().setprev(node); head.setnext(node); size++; } |

B. | public class insertfront(int data) { node node = new node(data, head, head); node.getnext().setprev(node); head.setnext(node); size++; } |

C. | public class insertfront(int data) { node node = new node(data, head, head.getnext()); node.getnext().setprev(head); head.setnext(node); size++; } |

D. | public class insertfront(int data) { node node = new node(data, head, head.getnext()); node.getnext().setprev(node); head.setnext(node.getnext()); size++; } |

Answer» A. public class insertfront(int data) { node node = new node(data, head, head.getnext()); node.getnext().setprev(node); head.setnext(node); size++; } |

View all MCQs in:
Data Structure (DS)

- Which of the following statement is true?i) Using singly linked lists and circular list, it is not possible to traverse the list backwards.ii) To find the predecessor, it is required to traverse the list from the first node in case of singly linked list.
- Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are: i. isEmpty (Q) — returns true if the queue is empty, false otherwise. ii. delete (Q) — deletes the element at the front of the queue and returns its value. iii. insert (Q, i) — inserts the integer i at the rear of the queue. Consider the following function: void f (queue Q) { int i ; if (!isEmpty(Q)) { i = delete(Q); f(Q); insert(Q, i); } }What operation is performed by the above function f ?
- If in a linked list address of first node is 1020 then what will be the address of node at 5th position ?
- In ……………, search start at the beginning of the list and check every element in the list.
- To insert element at start, the previous pointer of newly added node would point to ______
- Any node is the path from the root to the node is called
- node.next -> node.next.next; will make
- What is the functionality of the following code? Choose the most appropriate answer. public int function() { if(head == null) return Integer.MIN_VALUE; int var; Node temp = head; Node cur; while(temp.getNext() != head) { cur = temp; temp = temp.getNext(); } if(temp == head) { var = head.getItem(); head = null; return var; } var = temp.getItem(); cur.setNext(head); return var; }
- Each node in a linked list has two pairs of ………….. and ……………….
- A linear list in which each node has pointers to point to the predecessor and successors nodes is called as ..

Login to Continue

It will take less than 2 minutes

Report MCQ