Question: -------------------------- LinkedList.java ----------------------------- public class LinkedList { // uses the Node class public Node headNode; // refers to dummy head node of the linked list-bookend
--------------------------
LinkedList.java
-----------------------------
public class LinkedList { // uses the Node class public Node headNode; // refers to dummy head node of the linked list-"bookend" public Node endNode; // refers to dummy end node of the linked list-"bookend" //Constructor establishes an empty linked list public LinkedList() { // sets up two linked dummy "bookend" nodes endNode=new Node(0,null); headNode=new Node(0,endNode); } //Methods public boolean IsEmpty() { return headNode.link==endNode; } public void InsertBegin(int item) { if(headNode.link==endNode) { // if the list is empty Node n = new Node(); n.datum=item; n.link=endNode; headNode.link=n; } else { Node n = new Node(); n.datum=item; n.link=headNode.link; headNode.link=n; } } public void InsertEnd(int item) { if( headNode.link==endNode) { // if the list is empty InsertBegin(item); } else { Node n = endNode; n.datum=item; endNode= new Node(0,null); n.link=endNode; } } public boolean Find(int item) { if (!IsEmpty()) { Node l = headNode.link; while ((l.datum != item)&& (l != endNode)) { l = l.link; } if (l.datum == item) return true; if (l == endNode) return false; } return false; } public void Delete(int item) { if (!IsEmpty() ){ Node l = headNode; Node m = headNode.link; while ((m != endNode) && (m.datum !=item)){ m = m.link; l= l.link; } if ((m != endNode)&& (m.datum==item)) { l.link=m.link; } } } // Method Display public void Display(){ System.out.println("The data in the linked list are:"); Node l = headNode.link; while (l != endNode) { System.out.println( l.datum); l = l.link; } } }------------------------
Orderinsert
-----------------------
public void OrderInsert(int item) {
Node n = new Node();
n.datum=item;
if (IsEmpty()) {
InsertBegin(item);
} else {
if(item
n.link = headNode.link;
headNode.link = n;
} else {
Node p = headNode.link;
Node pprev = headNode.link;
while ((p!=null) &&(p!=endNode) &&(item>p.datum)) {
pprev=p;
p=p.link;
}
pprev.link=n;
n.link=p;
}
}
------------------------------------------
(Node.java, incase you need it)
--------------------------------
//Node.java
public class Node {
public int datum;
public Node link;
public Node ()
{
datum =0;
link= null;
}
public Node(int d,Node l)
{
datum = d;
link = l;
}
}
--------------------
Question:

(java, reiploaded question with correct code)
The "mystery method" is the code at the bottom called order insert which i have already renamed and fixed i think?
Nothing should be deleted on the "linkedlist" also the "orderinsert" is to be placed inside the "linkedlist" and fix any errors it has, i am having trouble writing the A7Main program.
P.S: This question has been posted before but they used a different "OrderInsert" i would like it done using the one i have above.
Assuming that the Mystery method does "the right thing", change its name to public void OrderInsert(int item) and include it in your LinkedList.java file. Then write a Main program, A7Main.java to OrderInsert the items 12, 3, 7, 20, 15, 32, 6, 11 and then print out the list to verify that the list is indeed in ascending order
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
