Please answer in Java code
Specify the list-based implementation for a enqueue() and dequeue() method of the Queue ADT.
Here i have created 3 java classes. One is interface(Queue.java), and other two are java Classes. LinkedListQueue.java is architecture of queue, and LinkedQueueDemo.java used for perform operation on queue.
/*************************** Queue.java Starts here ********************************/
package com.test.test2;
public interface Queue <Item> extends Iterable <Item>
{
Item dequeue(); // removes an item from the front of the queue
void enqueue(Item item); // adds an item to the rear end of the queue
boolean isEmpty(); // returns true if queue is empty, false otherwise
int size(); // returns the number of items in the queue right now
}
/*************************** Queue.java Ends here ********************************/
/*************************** LinkedQueue.java Starts here ********************************/
package com.test.test2;
import java.lang.Iterable;
import java.util.*;
class LinkedQueue <Item> implements Queue <Item>
{
private Node front, rear; //begin and end nodes
private int size; // number of items
private class Node
{
Item item;
Node next;
}
public LinkedQueue()
{
front = null;
rear = null;
size = 0;
}
public boolean isEmpty()
{
return (size == 0);
}
public Item dequeue()
{
Item item = front.item;
front = front.next;
if (isEmpty())
{
rear = null;
}
size--;
return item;
}
public void enqueue(Item item)
{
Node oldRear = rear;
rear = new Node();
rear.item = item;
rear.next = null;
if (isEmpty())
{
front = rear;
}
else
{
oldRear.next = rear;
}
size++;
}
public int size()
{
return size;
}
public Iterator<Item> iterator()
{
return new LinkedQueueIterator();
}
private class LinkedQueueIterator implements Iterator <Item>
{
private int i = size;
private Node first = front; //the first node
public boolean hasNext()
{
return (i > 0);
}
public Item next()
{
Item item = first.item;
first = first.next;
i--;
return item;
}
public void remove()
{
// not needed
}
}
}
/*************************** LinkedQueue.java Ends here ********************************/
/*************************** LinkedQueueDemo.java Starts here ********************************/
package com.test.test2;
public class LinkedQueueDemo
{
public static void main (String a[])
{
Queue <Integer> q = new LinkedQueue<Integer>();
System.out.println("Inserting Items in queue : ");
q.enqueue(11);
q.enqueue(22);
q.enqueue(33);
q.enqueue(44);
q.enqueue(55);
q.enqueue(55);
System.out.println("Queue after inserting items : ");
for (Integer i : q) {
System.out.println(i);
}
System.out.println("\nDelete an item from queue: " + q.dequeue());
System.out.println("\nTotal Size of the queue: " + q.size());
System.out.println("\nNow the queue is:");
for (Integer i : q)
System.out.println(i);
}
}
/*************************** LinkedQueueDemo.java Ends here ********************************/
OUTPUT >>>>>>>>>
Inserting Items in queue :
Queue after inserting items :
11
22
33
44
55
55
Delete an item from queue: 11
Total Size of the queue: 5
Now the queue is:
22
33
44
55
55
Please answer in Java code Specify the list-based implementation for a enqueue() and dequeue() method of...
Python use dequeue and enqueue methods, alter the dequeue method and the enqueue method. remove items from the first element of the list (the front of the queue) and return this value and you need to add items to the last element of the list (the rear of the queue). 4. (20 points) Programming Exercise 5 from Chapter 3 of your textbook. Name the class Queuex, and use the other method names given in Chapter 3.11 in your digital textbook....
Create a flowchart to represent the Push and Pop operations for a Stack based on a linked list data structure. Create a flowchart to represent the Enqueue and Dequeue operations for a Queue based on a linked list data structure. Write the required Java code to implement either a Stack or a Queue data structure based on a linked list. The code should include the class constructors, the necessary properties, and methods to add and remove elements from the data...
Create a Java code that includes all the methods from the Lecture slides following the ADTs LECTURE SLIDES Collect/finish the Java code (interface and the complete working classes) from lecture slides for the following ADTS: 4) Queue ADT that uses a linked list internally (call it LQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! For each method you develop, add comments and estimate the big-O running time of its algorithm....
Collect/finish the Java code (interface and the complete working classes) from lecture slides for the for the following ADT: 3) Queue ADT that uses an array internally (call it AQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! Make sure your classes implement the corresponding interfaces. Put your classes in a package called cse11. Try to make the code robust and try to use generics. The Queue ADT The Queue ADT...
please write them in parts and not the whole code Page 3 of 5 based queue - coding question rray-based fine an array-bag ray-based queue template class ArrQueue that uses a one-dimensional circular array esent the queue. The class consists of member variables: items, front, back, count. Wher functions: enqueue, dequeue, is Empty, peek Front. to represent the queue ement/ write code for enqueue member function ment/ write code for dequeue member function
(JAVA)Define a method getFrequency(anEntry) for the Linked List implementation of stack ADT. The method returns the number of occurrences of anEntry in the stack.
In java Build a QueueInt class for integers that is compatible with the driver code below. The QueueInt should operate in a FIFO (first in, first out) fashion and implement the variables and methods also listed below: Data Members: Declare and initialize, as needed, the data item(s) you will need to manage a queue of integers. You may only use arrays and primitives for your instance and/or static variables (I,e You can’t use Java defined Queue / Stack / List...
You need to implement a queue based on the doubly linked list. (In C++) **PLEASE follow the format** **Don't worry about the readme.txt** THANK YOU SO SO MUCH! You have to implement the doubly linked list in DList.h and DList.cpp and the queue in the LinkedQueue.h and LinkedQueue.cpp; all as template classes. You have to provide the main.cpp file as we discussed in class to allow the user to interact with your queue using enqueue, dequeue, front, back, size, empty,...
It is C++ problems, please explain your each line of code as well. Task 1: Implement/ Hard Code a Doubly Linked Lists and make it a Stack. Do not use ::list:: class from the STD library for this example. The user will input a string and the program will output the string backwards. Displaying correct Stack implementation. Utilize the conventional static methods as needed. push() pop() empty() peek() peek() Sample Execution Please input String: happy yppah Task 2: Implement /...
4. In an array-based implementation of the ADT list, what is the best case performance of the contains method? a. O(1) b. O(log n) C. O(n) d. O(nº) 5. In an array-based implementation of the ADT list, what is the worst case performance of the contains method? a. O(n) b. O(n) C. O(log n) d. 0(1) 6. In an array-based implementation of the ADT list, what is the performance of the contains method when the entry is not in the...