ShmoopTube
Where Monty Python meets your 10th grade teacher.
Search Thousands of Shmoop Videos
AP Computer Science A Videos 108 videos
AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?
AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?
AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism. Which of the following will satisfy the conditional if statement for boo, str,...
AP Computer Science 4.4 Standard Data Structures 177 Views
Share It!
Description:
AP Computer Science: Standard Data Structures Drill 4, Problem 4. What does the following code produce?
Transcript
- 00:00
Thank you We sneak And here's your shmoop du jour
- 00:05
And we're about to skip more lines than a lip
- 00:08
sinking Britney spears All right what is the following code
- 00:11
produced Iron my arm my arm i r All right
- 00:18
and here your potential answers on a number of and
Full Transcript
- 00:20
a whole lot of nothing Okay so let's see what
- 00:23
we've got here the first eleven lines creating a ray
- 00:25
list called mei are then populates it with ten elements
- 00:29
each being imagers counting upward from zero being that no
- 00:33
raise indexing scheme also begins it Zero it looks like
- 00:36
we're going to start with an array with values that
- 00:38
match their indices The four loose gives us an id
- 00:42
aerator called acts that starts with the value of zero
- 00:45
and terminates when x is no longer less than the
- 00:48
size of the array list Well what it actually does
- 00:51
in the loop however is a little tricky Let's get
- 00:54
out the old number line and some elements and work
- 00:56
it out visually Each time the loop cycles it'll be
- 01:00
printing something to the console the product of a remove
- 01:03
statement The remove statement physically removes the given indexes element
- 01:07
from the array list and returns the value of the
- 01:10
removed item which is what will be printing after some
- 01:13
things removed however the remaining elements shift upward in line
- 01:17
the indices for every value that came after Are gonna
- 01:20
change hence the potential for confusion and why we even
- 01:23
have to answer a question like this in the first
- 01:25
place And now the first time running through the loop
- 01:28
x will be zero and the print line and remove
- 01:31
statement will remove in print the element at index zero
- 01:35
Zero The remaining elements move up a space x is
- 01:38
now one so we're removing print the element at index
- 01:41
one which is now two things move up again Ex
- 01:44
becomes too so we remove and print The element at
- 01:46
index to which is four x is now three and
- 01:49
the element of index three is now six Acts becomes
- 01:52
4 and we're removing in printing in eight and the
- 01:54
lupus now terminate because excess five and five is no
- 01:58
longer less than the array list length In effect this
- 02:02
code snippet is a really fancy way to print every 00:02:04.98 --> [endTime] other number Clever and our answer is c
Related Videos
AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?
AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?
AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?
AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism. Which of the following will satisfy the conditional if statement for boo, str,...
AP Computer Science 4.2 Standard Algorithms. What kind of algorithm is the following?