Importance of time

Hi Can you help me out with this approach ?

<------------------------------------->

import java.util.Stack;
import java.util.Scanner;
public class Main {

public void nProcesses(QueueD call, QueueD actual) throws Exception{

int time = 0;

if(call.front() == actual.front()){
    time++;

    call.dequeue();
    actual.dequeue();

}else{

    while(call.front() != actual.front()){
    
    int tp = call.front();

    call.dequeue();

    call.enqueue(tp);

    time++;

    }

    time++;

    call.dequeue();

    actual.dequeue();

    System.out.println(time);
}

}
public static void main(String[] args) throws Exception{

     Main obj = new Main();
     QueueD callingQueue = obj.new QueueD();
     QueueD actualQueue = obj.new QueueD();

     Scanner s = new Scanner(System.in);

     int n = s.nextInt();

     for(int i = 0 ; i < n ; i++){

         callingQueue.enqueue(s.nextInt());
     }

     for(int j =  0 ; j < n ; j++){
         actualQueue.enqueue(s.nextInt());
     }

    nProcesses(callingQueue,actualQueue);

 }

 public class QueueD{

StacksUsingArrays primary;
StacksUsingArrays secondary;
public QueueD() throws Exception {
// TODO Auto-generated constructor stub
primary = new StacksUsingArrays();
secondary = new StacksUsingArrays();

         }
	

    

    public void enqueue(int data) throws Exception{
     while(!primary.isEmpty()){

         secondary.push(primary.pop());

     }
     primary.push(data);

     while(!secondary.isEmpty()){

         primary.push(secondary.pop());
     }
     }

     public boolean isEmpty(){

         return primary.isEmpty();
     }

     public int dequeue() throws Exception{

        return primary.pop();
     }

     public int front() throws Exception{

         return primary.top();
     }

     public void display() throws Exception{

         primary.display();
     }
 }

private class StacksUsingArrays {
private int[] data;
private int tos;

	public static final int DEFAULT_CAPACITY = 10;

	public StacksUsingArrays() throws Exception {
		// TODO Auto-generated constructor stub
		this(DEFAULT_CAPACITY);
	}

	public StacksUsingArrays(int capacity) throws Exception {
		if (capacity <= 0) {
			System.out.println("Invalid Capacity");
		}
		this.data = new int[capacity];
		this.tos = -1;
	}

	public int size() {
		return this.tos + 1;
	}

	public boolean isEmpty() {
		if (this.size() == 0) {
			return true;
		} else {
			return false;
		}
	}

	public void push(int item) throws Exception {
		if (this.size() == this.data.length) {
		    
		    int[] temp = new int[2 * data.length];
		    for(int i = 0;i < data.length;i++){
		        temp[i] = data[i];
		    }
		    
		    data = temp;
		}
		this.tos++;
		this.data[this.tos] = item;
	}

	public int pop() throws Exception {
		if (this.size() == 0) {
			throw new Exception("Stack is Empty");
		}
		int retVal = this.data[this.tos];
		this.data[this.tos] = 0;
		this.tos--;
		return retVal;
	}

	public int top() throws Exception {
		if (this.size() == 0) {
			throw new Exception("Stack is Empty");
		}
		int retVal = this.data[this.tos];
		return retVal;
	}

	public void display() throws Exception {
		if (this.size() == 0) {
			throw new Exception("Stack is Empty");
		}
		for (int i = this.tos; i >= 0; i--) {
			System.out.print(this.data[i] + " ");
		}

	}

}

}

problem lies in above method:
you are actually executing a single process while we need to execute all the process.
you can do it in 2 ways:

  1. make time as global variable and call nProcess method recursively with base condition when call queue becomes empty.
    or
  2. use a loop that iterates till one of the queue is empty.

Thanks

Thank you I got it now !

please resolve it and rate it thanks