Question

In: Computer Science

Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num ==...

Q1:

Given the following code, what is returned by tq(4)?

int tq(int num){

if (num == 0) return 0;

else

if (num > 100) return -1;

else

    return num + tq( num – 1 );

}

Group of answer choices:

0

4

-1

10


Q2:

Given that values is of type LLNode<Integer> and references a linked list (non-empty) of Integer objects, what does the following code do if invoked as mystery(values)?

int mystery(LLNode<Integer> list)

{

   if (list.getLink() == null)

      return list.getInfo();

   else

      return mystery(list.getLink());

}

Group of answer choices:

returns sum of the numbers on the values list

returns the last number on the values list

returns 0

returns how many numbers are on the values list

Q3:

Given that values is of type LLNode<Integer> and references a linked list (possibly empty) of Integer objects, what does the following code do if invoked as mystery(values)?

int mystery(LLNode<Integer> list)

{

   if (list == null)

      return 0;

   else

      return 1 + mystery(list.getLink());

}

Group of answer choices:

returns 0

returns sum of the numbers on the values list

returns the last number on the values list

returns how many numbers are on the values list

Solutions

Expert Solution


Related Solutions

What will the following code segments print on the screen? int num = 3; switch (num){...
What will the following code segments print on the screen? int num = 3; switch (num){             case 1:                         System.out.println(“Spring”); case 2:                         System.out.println(“Summer”); case 3:                         System.out.println(“Autumn”); case 4:                         System.out.println(“Winter”); }
What is the ouput of the following code? void loop(int num) { for(int i = 1;...
What is the ouput of the following code? void loop(int num) { for(int i = 1; i < num; ++i) { for(int j = 0; j < 5; ++j) { cout << j; } } } int main() { loop(3); return 0; }
What output is produced by the following code fragment? int num = 0, max = 20;...
What output is produced by the following code fragment? int num = 0, max = 20; while (num < max) { System.out.println(num); num += 4; }
5C++ Questions 1. What will the following code print? num = 8; cout << --num <<...
5C++ Questions 1. What will the following code print? num = 8; cout << --num << " "; cout << num++ << " "; cout << num; 2.Since the while loop evaluates the condition before executing the statement(s), it is known as a(n)____ loop, whereas the do-while loop evaluates the condition after the statements have been executed, it is known as a(n)____ loop. 3.T/F While loops can only be used when a counter is decremented to zero. If the counter...
Viewing the code snippet below answer the following questions: int num=10; do {      cout << “Hello”...
Viewing the code snippet below answer the following questions: int num=10; do {      cout << “Hello” << endl;      num--; } while(num > 1); After the above code is executed: “Hello” printed how many times: ___________ What is value ofnum:  ____________ language is c++
(True or False) The following function will compile. void print(int num) { return num+1; } Group...
(True or False) The following function will compile. void print(int num) { return num+1; } Group of answer choices True False Flag this Question Question 2 10 pts (True or False) The following code will output "I was true". bool isGreater(string s1, string s2) { if(s1 > s2) { return true; } return false; } int main() { if(isGreater("before","back")) { cout << "I was true"; } else { cout << "I was false"; } return 0; } Group of answer...
What is the output of the following piece of Java code? int id = 4; double...
What is the output of the following piece of Java code? int id = 4; double grossPay = 81.475; String jobType = "Intern"; System.out.printf("Id: %d, Type: %s, Amount:%.2f", id,grossPay,jobType); Select one: Error Id: 4, Type: Intern, Amount: $81.475 Id: 4, Type: $81.475, Amount: Intern Id: 4, Type: $81.48, Amount:Intern Id: 4, Type: Intern, Amount: $81.48
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are...
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are that it returns an array of all the elements of the int[] array numbers which are coprime with x } Note that the array that is returned may be an empty array--you will have to count how many times gcf(x, numbers[i]) == 1. ASSUME numbers is not null and not empty.
Given int B[4][4]={...}; Write a code segment that exchange the values about the main diagonal of...
Given int B[4][4]={...}; Write a code segment that exchange the values about the main diagonal of the matrix.
1)What is the output of the following code? struct someType { int a; int b; };...
1)What is the output of the following code? struct someType { int a; int b; }; void f1(someType &s) { s.a = 1; s.b = 2; } someType f2(someType s) { someType t; t = s; s.a = 3; return t; } int main() { someType s1, s2; f1(s1); s2 = f2(s1); cout << s1.a << '-' << s1.b << '-' << s2.a << '-' << s2.b << '-' << endl; return 0; } ------------------------------------------------------------------------------------------------------------------ 2) struct dateType { int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT