Ask Question
1 August, 02:13

Suppose list1 is a vector and list2 is a LinkedList. Both contain 1 million double values. Analyze the following code: for (int i = 0; i < list1. size (); i++) sum + = list1[i]; for (int i = 0; i < list2. getSize (); i++) sum + = list2. get (i);

+4
Answers (1)
  1. 1 August, 05:42
    0
    Code 1: - for (int i = 0; i < list1. size (); i++) sum + = list1[i];

    It will run perfectly and add the elements to the sum variable. The sum will totally depend that the sum is within the range of double variable. If it is out of range then there will be error out of bounds.

    Code 2: - for (int i = 0; i < list2. getSize (); i++) sum + = list2. get (i);

    This code will give syntax error because there is no getSize () method. For linked list there is size () method which determines the size of the list.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Suppose list1 is a vector and list2 is a LinkedList. Both contain 1 million double values. Analyze the following code: for (int i = 0; i < ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers