Select The Appropriate Code That Inserts Elements Into The List #145
Select the appropriate code that inserts elements into the list based on the given key value.<br /> (head and trail are dummy nodes to mark the end and beginning of the list, they do not contain any priority or element)
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 - Priority Queue - Quiz No.1.
Select the appropriate code that inserts elements into the list based on the given key value.
(head and trail are dummy nodes to mark the end and beginning of the list, they do not contain any priority or element)
(head and trail are dummy nodes to mark the end and beginning of the list, they do not contain any priority or element)
public void insert_key(int key,Object item) { if(key<0) { Systerm.our.println("invalid"); System.exit(0); } else { Node temp = new Node(key,item,null); if(count == 0) { head.setNext(temp); temp.setNext(trail); } else { Node dup = head.getNext(); Node cur = head; while((key>dup.getKey()) && (dup!=trail)) { dup = dup.getNext(); cur = cur.getNext(); } cur.setNext(temp); temp.setNext(dup); } count++; } }
public void insert_key(int key,Object item) { if(key<0) { Systerm.our.println("invalid"); System.exit(0); } else { Node temp = new Node(key,item,null); if(count == 0) { head.setNext(temp); temp.setNext(trail); } else { Node dup = head.getNext(); Node cur = dup; while((key>dup.getKey()) && (dup!=trail)) { dup = dup.getNext(); cur = cur.getNext(); } cur.setNext(temp); temp.setNext(dup); } count++; } }
public void insert_key(int key,Object item) { if(key<0) { Systerm.our.println("invalid"); System.exit(0); } else { Node temp = new Node(key,item,null); if(count == 0) { head.setNext(temp); temp.setNext(trail); } else { Node dup = head.getNext(); Node cur = head; while((key>dup.getKey()) && (dup!=trail)) { dup = dup.getNext(); cur = cur.getNext(); } cur.setNext(dup); temp.setNext(cur); } count++; } }
public void insert_key(int key,Object item) { if(key<0) { Systerm.our.println("invalid"); System.exit(0); } else { Node temp = new Node(key,item,null); if(count == 0) { head.setNext(temp); temp.setNext(trail); } else { Node dup = head.getNext(); Node cur = head; while((key>dup.getKey()) && (dup!=trail)) { dup = cur cur = cur.getNext(); } cur.setNext(dup); temp.setNext(cur); } count++; } }
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