Question: Complete the implementation of the class SortedLL in SortedLL.java which implements a sorted linked list using a sentinel node (dummy z node). If you can

  • Complete the implementation of the class SortedLL in SortedLL.java which implements a sorted linked list using a sentinel node (dummy z node). If you can get insert(int x) to work, then try remove(int x). Solution.

  • Demanding exercise: then modify and save under a new name: SortedLL2.java so that it does not use a sentinel. Is the code very different?

// Sorted linked list with a sentinel node // Skeleton code import java.util.Scanner;

class SortedLL { // internal data structure and // constructor code to be added here // this is the crucial method public void insert(int x) { Node prev, curr, t; } /* public boolean remove(int x) { Node prev, curr; } public boolean isEmpty() { } */ public void display() { Node t = head; System.out.print(" Head -> "); while( t != z) { System.out.print(t.data + " -> "); t = t.next; } System.out.println("Z "); } public static void main(String args[]) { SortedLL list = new SortedLL(); //list.display(); double x; int i, r; /* for(i = 1; i <= 5; ++i) { x = (Math.random()*100.0); r = (int) x; System.out.println("Inserting " + r); list.insert(r); list.display(); } */ /* while(!list.isEmpty()) { System.out.println(" Input a value to remove: "); Scanner in = new Scanner(System.in); r = in.nextInt(); if(list.remove(r)) { System.out.println(" Successfully removed: " + r); list.display(); } else System.out.println(" Value not in list"); } */ } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!