Answer:
c. 4
Explanation:
This will work as following:
Lets say first Tammie is inserted by this statement insertSorted("Tammie")
Next insertSorted("Brenda") statement adds Brenda on top of Tammie so the sequence is now
- Brenda
- Tammie
Next insertSorted("Sarah"); statement inserts Sarah below Brenda and above Tammie so the sequence becomes:
- Brenda
- Sarah
- Tammie
Next insertSorted("Tom"); statement inserts Tom below Tammie so the sequence becomes:
- Brenda
- Sarah
- Tammie
- Tom
Lastly insertSorted("Carlos"); statement inserts Carlos above sarah and below brenda so the sequence becomes:
- Brenda
- Carlos
- Sarah
- Tammie
- Tom
Now the statement getPosition("Tammie") is called which returns the position value of Tammie. So as you can see above its position is 4th so output is 4.