Ask Question
16 May, 02:05

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. 16 May, 04:52
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers