Ask Question
17 November, 13:37

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);

+1
Answers (1)
  1. 17 November, 13:56
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers