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

I need help with this Java Data Structures assignment. Thanks Runtime Interface

ID: 3804080 • Letter: I

Question

I need help with this Java Data Structures assignment. Thanks

Runtime Interface Methods

public interface RunTimeInterface {

   public static enum TimeUnits {Seconds, MilliSeconds, MicroSeconds, NanoSeconds};
   public static enum MemoryUnits {Bytes, KiloBytes, MegaBytes};
   public TimeUnits getTimeUnits();
   public void setTimeUnits(TimeUnits timeUnits);
   public MemoryUnits getMemoryUnits();
   public void setMemoryUnits(MemoryUnits memoryUnits);
   public double getLastRunTime();
   public double getLastMemoryUsage();
   public double[] getRunTimes();
   public double[] getMemoryUsages();
   public void resetRunTimes();
   public void addRuntime(long runTime);
   public double getAverageRunTime();
   public double getAverageMemoryUsage();
  
}

Queue Interface

Stack Interface

Iterable Interface

Iterator Interface

Node Class

Driver Interface

Details 1. RunTime Class You will be expanding the functionality of the RunTime class to implement the expanded RunTime Interface The interface may be downloaded from RunTimeInterface.iava 2. Array Based Queue class You will write the ArrayBasedgueue.java class which will implement the Queue Interface The interface may be downloaded from QueueInterface.iava. Please note that Queue Interface extends the Iterable Interface. See the Information On The Iterable Interface below 3. Linked Queue Class You will write the Linkedgueue. java class which will implement the Queue Interface. The interface may be downloaded from QueueInterfaceiava. Please note that Queue Interface extends the Iterable Interface. See the Information On The Iterable Interface below. Also note that the Linked Queue Class should be a Doubly Linked Queue. 4. Array Based Stack Class You will write the ArrayBasedstack. java class which will implement the Stack Interface. The interface may be downloaded from StackInterface.iava. Please note that Stack Interface extends the Iterable Interface See the Information On The Iterable Interface below.

Explanation / Answer

//Array based Queue class;

class ArrayBasedQueue
{
String [] array;
int rear;
int front;
int size;
int length;
  
public ArrayBasedQueue(int n)
{
this.array = new String[n];
rear = front = -1;
size = n;
length = 0;
}
  
public String dequeue()
{
if(isEmpty())
{
System.out.println("Queue does not have any element");
return "";
}
else
{
String s = array[front];
length--;
if(front == rear)
front = rear = -1;
else front++;
return s;
  
}
}
  
public boolean isEmpty()
{
return front == -1;
}
  
public void enqueue(String s)
{
if(rear + 1 >= size)
{
System.out.println("Queue is already full");
return;
}
else if(rear == -1)
{
front = rear = 0;
array[front] = s;
}
else
array[++rear] = s;
length++;
  
}
  
public String peek()
{
if(front == -1)
{
System.out.println("No elements in Queue");
return "";
}
return array[front];
}
  
public int size()
{
return length;
}
  
public void removeAll()
{
front = rear = -1;
}
  
public String dequeue(int index)
{
if(isEmpty())
{
System.out.println("Queue does not have any element");
return "";
}
else if(index < 0 || index >= size || index > length - 1)
{
System.out.println("Invalid index");
return "";
}
else
{
String s = array[index + front];
length--;
  
if(index + front == rear)
rear--;
  
else if(front == rear)
front = rear = -1;
  
else
{
String[] a = Arrays.copyOfRange(array, 0, front+index-1);
String[] b = Arrays.copyOfRange(array,front+index+1, size);
for(int i =0; i< a.length + b.length; i++)
{
if(i <a.length)
{
array[i] = a[i];
}
else
array[i] = b[i];
}
rear--;
}
return s;
  
}
}
}

// Linked List based Queue

class doublyLinkedList
{
String data;
doublyLinkedList prev;
doublyLinkedList next;
  
  
public doublyLinkedList(String s)
{
data = s;
prev = next = null;
}
}
class LinkedQueueClass
{
doublyLinkedList front, rear;
int size;
  
public LinkedQueueClass()
{
front = rear = null;
size = 0;
}
  
public int size()
{
return size;
}
  
public void removeAll()
{
front = rear = null;
size = 0;
}
  
public String peek()
{
if(front != null)
return front.data;
else
{
System.out.println("Queue is empty");
return "";
}
}
  
public boolean isEmpty()
{
return size == 0;
}
  
public void enqueue(String s)
{
doublyLinkedList newNode = new doublyLinkedList(s);
  
if(rear == null)
{
front = rear = newNode;
size++;
}
else
{
newNode.prev = rear;
rear.next = newNode;
rear = newNode;
size++;
}
}
  
public String dequque()
{
if(isEmpty())
{
System.out.println("Queue is empty");
return "";
}
else if(front == rear)
{
size = 0;
String s = rear.data;
front = rear = null;
return s;
}
else
{
size--;
String s = front.data;
front = front.next;
front.prev = null;
return s;
}
}
  
public String dequeue(int index)
{
if(isEmpty() || index > size || index < 1)
{
System.out.println("Invalid index or Queue is empty");
return "";
}
else
{
doublyLinkedList temp = front;
int count=1;
while(count < index)
{
temp = temp.next;
count++;
}
String s = temp.data;
temp.prev.next = temp.next;
if(temp.next != null)
temp.next.prev = temp.prev;
  
temp.prev = temp.next = null;
size--;
return s;
}
}
  
}

// Stack implementation using Array

public class ArrayStack
{
int top;
int size;
String[] array;
  
public ArrayStack(int c)
{
size = 0;
array = new String[c];
top = -1;
}
  
public void clear()
{
top = -1;
size = 0;
}
  
public boolean isEmpty()
{
return top == -1;
}
  
public String peek()
{
return array[top];
}
  
public String pop()
{
if(isEmpty())
{
System.out.println("Stack is empty");
return "";
}
else
{
String s = array[top--];
size--;
return s;
}
}
  
public void push(String s)
{
if(top == array.length-1)
{
System.out.println("Stack overflow");
}
else
{
array[++top] = s;
size++;
}
}
  
public int size()
{
return size;
}
}

// Linked Stack Class

class doublyLinkedList
{
String data;
doublyLinkedList prev;
doublyLinkedList next;
  
  
public doublyLinkedList(String s)
{
data = s;
prev = next = null;
}
}
  
class LinkedStackClass
{
doublyLinkedList top;
int size;
  
public LinkedStackClass()
{
top = null;
size = 0;
}
  
public void clear()
{
top.prev = null;
top = null;
size = 0;
}
  
public boolean isEmpty()
{
return size == 0;
}
  
public String peek()
{
if(top == null)
{
System.out.println("Stack Is empty");
return "";
}
else
{
return top.data;
}
}
  
public String pop()
{
if(isEmpty())
{
System.out.println("Stack Is empty");
return "";
}
else
{
String s = top.data;
if(size == 1)
{
top = null;
size = 0;
}
else
{
top = top.prev;
top.next = null;
size--;
}
return s;
}
}
  
public void push(String s)
{
doublyLinkedList newNode = new doublyLinkedList(s);
if(size == 0)
top = newNode;
else
{
top.next = newNode;
newNode.prev = top;
top = top.next;
}
size++;
}
  
public int size()
{
return size;
}
}