Answer:
The solution code is written in Java
- public static void checkCommonValues(int arr1[], int arr2[]){
- if(arr1.length < arr2.length){
- for(int i = 0; i < arr1.length; i++){
- for(int j = 0; j < arr2.length; j++){
- if(arr1[i] == arr2[j]){
- System.out.print(arr1[i] + " ");
- }
- }
- }
- }
- else{
- for(int i = 0; i < arr2.length; i++){
- for(int j = 0; j < arr1.length; j++){
- if(arr2[i] == arr1[j]){
- System.out.print(arr2[i] + " ");
- }
- }
- }
- }
- }
Explanation:
The key idea of this method is to repeated get a value from the shorter array to check against the all the values from a longer array. If any comparison result in True, the program shall display the integer.
Based on this idea, an if-else condition is defined (Line 2). Outer loop will traverse through the shorter array (Line 3, 12) and the inner loop will traverse the longer array (Line 4, 13). Within the inner loop, there is another if condition to check if the current value is equal to any value in the longer array, if so, print the common value (Line 5-7, 14-16).
=(Happy)&(Birthday) this is how it would be formatted
Answer:
10
Explanation:
An enqueue operation is a function that adds an element(value) to a queue array. A dequeue operations removes an element from a queue array. Queue arrays follow a first-in-first-out approach, so elements that are first stored in the queue are removed/accessed first(enqueue operations add elements at the rear of the queue array).
The following operations leave 10 elements in the queue of array size 12 after its done:
10 enqueue operations= adds 10 elements
5 dequeue operations= removes 5 elements( 5 elements left in queue)
6 enqueue operations= adds 6 elements(11 elements in queue)
10 dequeue operations= removes 10 elements(1 element left in queue)
8 enqueue operations= adds 8 elements(9 elements in queue)
2 dequeue operations= removes 2 elements(7 elements left in queue)
3 enqueue operations= adds 3 elements(10 elements in queue)
Therefore there are 10 elements in the queue after enqueue and dequeue operations.
Yes that is correct. Was there a specific question you wanted answered...