Introduction To Data Structures - Study Mode

[#206] What is the output of the following Java code? public class CircularQueue
{
protected static final int CAPACITY = 100
protected int size,front,rear
protected Object q[]
int count = 0
public CircularQueue()
{
this(CAPACITY)
}
public CircularQueue (int n)
{
size = n
front = 0
rear = 0
q = new Object[size]
}


public void enqueue(Object item)
{
if(count == size)
{
System.out.println("Queue overflow")
return
}
else
{
q[rear] = item
rear = (rear+1)%size
count++
}
}
public Object dequeue()
{
if(count == 0)
{
System.out.println("Queue underflow")
return 0
}
else
{
Object ele = q[front]
q[front] = null
front = (front+1)%size
count--
return ele
}
}
public Object frontElement()
{
if(count == 0)
return -999
else
{
Object high
high = q[front]
return high
}
}
public Object rearElement()
{
if(count == 0)
return -999
else
{
Object low
rear = (rear-1)%size
low = q[rear]
rear = (rear+1)%size
return low
}
}
}
public class CircularQueueDemo
{
public static void main(String args[])
{
Object var
CircularQueue myQ = new CircularQueue()
myQ.enqueue(10)
myQ.enqueue(3)
var = myQ.rearElement()
myQ.dequeue()
myQ.enqueue(6)
var = mQ.frontElement()
System.out.println(var+" "+var)
}
}
Correct Answer

(A) 3 3

[#207] Which of the following is the correct way to declare a multidimensional array in Java?
Correct Answer

(C) int[][]arr

[#208] What is the functionality of the following piece of code? public void display()
{
if(size == 0)
System.out.println("underflow")
else
{
Node current = first
while(current != null)
{
System.out.println(current.getEle())
current = current.getNext()
}
}
}
Correct Answer

(B) display the list

[#209] What is the output of the following Java code? public class array
{
public static void main(String args[])
{
int []arr = {1,2,3,4,5}
System.out.println(arr[5])
}
}
Correct Answer

(C) ArrayIndexOutOfBoundsException