// add a delete method to class MyNameQueue !!!! // demonstrate that it works !!!! //CIT242 Data…

// add a delete method to class MyNameQueue !!!!
// demonstrate that it works !!!!
//CIT242 Data Structures
public class QueueApp {

public static void main(String[] args) {
MyNameQueue myQueue = new MyNameQueue();

System.out.println(“Welcome to my Queue.n”);
//populating the queue
myQueue.push(“Jack”, “Haley”);
myQueue.push(“A”, “A”);
myQueue.push(“John”, “Smith”);
myQueue.push(“Winston”, “Churchill”);
myQueue.push(“Nelson”, “Mandela”);
myQueue.push(“Mary”, “Jones”);

System.out.println(“before popping:”);
myQueue.printQueue();
System.out.println(“”);

System.out.println(“do a pop:”);
myQueue.pop();
System.out.println(“”);

System.out.println(“after popping:”);
myQueue.printQueue();
System.out.println(“”);

System.out.println(“count the queue:”);
myQueue.countQueue();
System.out.println(“”);
System.out.println(“”);

System.out.println(“after a listInsert (Walt Disney) :”);
myQueue.listInsert(“Walt”, “Disney”);
myQueue.printQueue();
System.out.println(“”);

}
}

class Entry {

String first;
String last;

public Entry(String first, String last) {
this.first = first;
this.last = last;
}

public String toString() {
//return “Entry{” + “first=” + first + “, last=” + last + ‘}’;
return first + ” ” + last;
}

}

class NODE {

Entry info;
NODE link;

public NODE(Entry info) {
this.info = info;
}

public NODE() {
info = new Entry(“”, “”);
}

}

class MyNameQueue {

NODE top;
NODE last;

public MyNameQueue() {
top = null;

}

public void push(String firstName, String lastName) {
Entry newEntry = new Entry(firstName, lastName);

NODE newRecord = new NODE();
newRecord.info = newEntry;
newRecord.link = null;

if (top == null) {
top = last = newRecord;
} else {
last.link = newRecord; //why?
last = newRecord;
}

}

public void printQueue() {
NODE newTop = top;

while (newTop != null) {
System.out.println(newTop.info.toString());
newTop = newTop.link;

}

}

public NODE pop() {

if (top == null) {
System.out.println(“the queue is empty.”);
return new NODE(); //return null;
} else {
NODE p = top;
top = top.link;
System.out.println(p.info.toString());
//p.link = null; //is this necessary????
return p;
}

}

public void countQueue() {
int i = 0;
NODE p = top;

while (p != null) {
i++;
p = p.link;
}

System.out.printf(“Total items in queue: %d”, i);
}

public void listInsert(String firstName, String lastName) {

Entry newEntry = new Entry(firstName, lastName);
NODE last, next;
next = top;
last = null; // is this necessary???? Yes, you might insert a new NODE before the top

while ((newEntry.last.compareTo(next.info.last) > 0) && (next.link != null)) {
last = next;
next = next.link;
System.out.println(“here”);
}

if (newEntry.last.compareTo(next.info.last) == 0) {
next.info = newEntry; //update
}
else
if (newEntry.last.compareTo(next.info.last) < 0) {
if (last == null) { //if the new entry should be insert before the top
NODE p = new NODE(newEntry);
p.link = top;
top = p;

} else {
last.link = new NODE();
last.link.info = newEntry;
last.link.link = next;
}
}
else {
// NODE temp = next.link; //store the link after next node before insert the new node after the next node
next.link = new NODE();
next.link.info = newEntry;
// next.link.link = temp;
next.link.link = null;
}

}

}

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
error: Content is protected !!