Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help coding this pseudocode for a Enqueue method in java. public void enq

ID: 3864002 • Letter: I

Question

I need help coding this pseudocode for a Enqueue method in java.

public void enqueue(TreeNode node)

—> bool flag = False

—> search for element with CompareTo function qual to zero

—> for each element in FrendshipQueue

—> if Element.comapreTo(node) == 0

—> flag = True —> if element has 2 children

—> continue the search

—> if the element has less than 2 children

—> append the TreeNode node to the element or its 1st

child

—> if flag == False

—> append the TreeNode node to the tail.

Explanation / Answer

public class myQueue { private Node front; private Node back; private int s; public myQueue() { front = null; back = null; s = 0; } public void enqueue(Object x) { if( isEmpty() ) back = front = new Node(x); else back = back.next = new Node(x); s++; } public Object dequeue() { Object x; if( isEmpty() ) { System.out.println("nothing to dequeue. queue empty."); } x = front.data; s--; return x; } public boolean isEmpty() { if(s == 0) return true; else return false; } public void printQueue() { if ( isEmpty() ) System.out.println("empty queue"); else { Node temp = back; while(temp != null) { System.out.println(temp); temp = temp.next; } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote