Choose The Code Which Performs The Store Operation In A Sparse #333
Choose the code which performs the store operation in a sparse array.(Linked list implementation)
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 Array Types - Sparse Array - Quiz No.1.
Choose the code which performs the store operation in a sparse array.(Linked list implementation)
public void store(int index, Object val) { List cur = this; List prev = null; List node = new List(index); node.val = val; while (cur != null && cur.index < index) { prev = cur; cur = cur.next; } if (cur == null) { prev.next = node; } else { if (cur.index == index) { System.out.println("DUPLICATE"); return; } prev.next = node; node.next = cur; } return; }
public void store(int index, Object val) { List cur = this; List prev = null; List node = new List(index); node.val = val; while (prev != null && prev.index < index) { prev = cur; cur = cur.next; } if (cur == null) { prev.next = node; } else { if (cur.index == index) { System.out.println("DUPLICATE"); return; } prev.next = node; node.next = cur; } return; }
public void store(int index, Object val) { List cur = this; List prev = null; List node = new List(index); node.val = val; while (cur != null && cur.index < index) { cur = cur.next; prev = cur; } if (cur == null) { prev.next = node; } else { if (cur.index == index) { System.out.println("DUPLICATE"); return; } prev.next = node; node.next = cur; } return; }
public void store(int index, Object val) { List cur = this; List prev = null; List node = new List(index); node.val = val; while (cur != null && prev.index < index) { cur = cur.next; prev = cur; } if (cur == null) { prev.next = node; } else { if (cur.index == index) { System.out.println("DUPLICATE"); return; } prev.next = cur; node.next = node; } return; }
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