Question

In: Computer Science

class LLNode<T> { public T info; public LLNode<T> link; public LLNode(T i, LLNode<T> l) { //...

class LLNode<T> {

public T info;

public LLNode<T> link;

public LLNode(T i, LLNode<T> l) { // constructor

info=i;

link=l;

}

}

class CircularLinkedQueue<T> {

private LLNode<T> rear = null; // rear pointer

public boolean isEmpty() {

/*checks if the queue is empty */

}

public int size() {

/* returns the number of elements in the queue */

}

public void enQueue(T element) {

/* enqueue a new element */

}

public T deQueue() {

/* dequeue the front element */

}

public String toString() {

String str = new String();

/* concatenate elements to a String */

return str;

}

}

Solutions

Expert Solution

public boolean isEmpty() {

   if(this.rear == null)
       return true;
   else
       return false;
}

public int size() {

   if(this.rear == null)
   {
       return 0;
   }
   else
   {
       LLNode<T> n = this.rear.link;
       int i=1;
       while(n!=this.rear)
       {
           i++;
           n=n.link;
       }
       return i;
   }
}

public void enQueue(T element) {

   if(this.rear == null)
   {
       this.rear.info = element;
       this.rear.link = this.rear;
   }
   else
   {
       LLNode<T> newNode = null;
       newNode.info = element;
       newNode.link = this.rear.link;
       this.rear.link=newNode;
       this.rear = newNode;
   }
}

public T deQueue() {

   if(this.rear.link == this.rear)
   {
       T e = this.rear.info;
       this.rear=null;
       return e;
   }
   else
   {
       T e = (this.rear.link).info;
       LLNode<T> newNode = this.rear.link;
       this.rear.link = (this.rear.link).link;
       newNode=null;
       return e;
   }
}

public String toString() {

String str = new String();
LLNode<T> n = this.rear.link;
while(n!=this.rear)
{
   str = str+"->"+n.info;
   n=n.link;
}
return str;
}


Related Solutions

public class Node<T> { Public T Item { get; set; } Public Node<T> Next; { get;...
public class Node<T> { Public T Item { get; set; } Public Node<T> Next; { get; set; } public Node (T item, Node<T> next) { … } } public class Polynomial { // A reference to the first node of a singly linked list private Node<Term> front; // Creates the polynomial 0 public Polynomial ( ) { } // Inserts term t into the current polynomial in its proper order // If a term with the same exponent already exists...
#ifndef PROJ7_MYVECTOR #define PROJ7_MYVECTOR #include "proj7-ContainerIfc.h" template <class T> class MyVector : public ContainerIfc<T> { public:...
#ifndef PROJ7_MYVECTOR #define PROJ7_MYVECTOR #include "proj7-ContainerIfc.h" template <class T> class MyVector : public ContainerIfc<T> { public: /** * MyVector * * This is the default constructor that sets size equal * to 0 and capacity to 10. * * Parameters: none * * Output: * return: none * reference parameters: none * stream: none */ MyVector(); /** * ~MyVector * * This is the destructor that deletes memory * * Parameters: none * * Output: * return: none * reference...
Assume that Animal is a class that has method void info() that prints "I am an...
Assume that Animal is a class that has method void info() that prints "I am an animal". Classes Bird and Reptile both extend class Animal, and both override method info(). Class Bird implements method info to print "I am a bird", and class Reptile implements method info to print "I am a reptile ". Determine the outcome printed by the following lines of code. Animal animal = new Animal(); animal.info(); //OUTCOME: animal = new Reptile() animal.info(); //OUTCOME: animal = new...
All the info is provided in the link provided on the bottom of this desciption. Use...
All the info is provided in the link provided on the bottom of this desciption. Use the Consolidated Statement of Income on page 85 of the link below is the 10k report for eTrade Financial Corporation. https://www.sec.gov/Archives/edgar/data/1015780/000101578017000030/etfc-20161231x10k.htm#sC725D2ED94A85BF0912C52C3FE195E9B Questiona: Create a spreadsheet in a common size income statement format for the most recent year and the year before. Create a % of sales for each item next to the amounts that are given on the 10k income statement.  Show on your spreadsheet...
how to sorted the list from another class!!! example i have a class public meso public...
how to sorted the list from another class!!! example i have a class public meso public meso(string id) public hashmap<string, integer> neou{ this class print out b d e c a now create another class public mesono public mesono(hashmap<string, integer> nei) //want to sorted meso class print list to this class!! // print out a b c d e } ( -------Java------)   
Using this BubbleSort implementation in Java: public class BubbleSort<T extends Comparable<T>> {    private static <T...
Using this BubbleSort implementation in Java: public class BubbleSort<T extends Comparable<T>> {    private static <T extends Comparable<T>>    void swap(T[] data, int index1, int index2)    {       T temp = data[index1];       data[index1] = data[index2];       data[index2] = temp;    }    public void sort(T[] data)    {       int position, scan;       for (position = data.length - 1; position >= 0; position--)       {          for (scan = 0; scan <= position - 1; scan++)          {...
Using Java The given class SetInterface.java is : public interface SetInterface<T> {    /**    *...
Using Java The given class SetInterface.java is : public interface SetInterface<T> {    /**    * Gets the current number of entries in this set.    *    * @return The integer number of entries currently in the set.    */    public int getSize();    /**    * Sees whether this set is empty.    *    * @return True if the set is empty, or false if not.    */    public boolean isEmpty();    /**    *...
Show the output of the following code. Assume the node is in the usual info-link form...
Show the output of the following code. Assume the node is in the usual info-link form with info of the type int. Also, list and ptr are reference variables of the type Node. list = new Node( ); list.info = 88; ptr = new Node( ); ptr.info = 41; ptr.link = null; list.link = ptr; ptr = new Node( ); ptr.info = 99; ptr.link = list; list = ptr; ptr = new Node( ); ptr.info = 19; ptr.link = list.link;...
public class CDLL_Node<T> { private T data; private CDLL_Node<T> prev, next; // EACH CDLL_Node PTS TO...
public class CDLL_Node<T> { private T data; private CDLL_Node<T> prev, next; // EACH CDLL_Node PTS TO ITS PREV & NEXT public CDLL_Node() { this( null, null, null ); // 3 FIELDS TO INIT } public CDLL_Node(T data) { this( data, null, null); } public CDLL_Node(T data, CDLL_Node<T> prev, CDLL_Node<T> next) { setData( data ); setPrev( prev ); setNext( next ); } public T getData() { return data; } public CDLL_Node<T> getPrev() { return prev; } public CDLL_Node<T> getNext() { return...
I needv pseudocode and a flowchart for the following java code public class AcmePay { public...
I needv pseudocode and a flowchart for the following java code public class AcmePay { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); int hours, shift, retirement = 0; do { System.out.print("Enter the number of hours worked (>0): "); hours = scanner.nextInt(); } while (hours <= 0); do { System.out.print("Enter shift [1 2 or 3]: "); shift = scanner.nextInt(); } while (shift < 1 || shift > 3); if (shift == 2 || shift ==...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT