1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
if n is the length of the given list, we have the
* following boundary conditions:
*
* if k==0:
* calling list unchanged and an empty list returned
* if k>=n:
* calling becomes empty and a list containing
* all elements previously in lst is returned.
*
* examples:
*
* EX1: lst: [2, 3, 9, 7, 8]
* k: 3
*
* call:
*
* List<int> * pre = lst.prefix(3);
*
* after call:
* lst: [7, 8]
* returned list (prefix): [2, 3, 9]
*
* EX2 lst: [2, 3, 9, 7, 8]
* k: 0
*
* call:
*
* List<int> * pre = lst.prefix(3);
*
* after call:
* lst: [2, 3, 9, 7, 8] (unchanged)
* returned list: []
*
* EX3 lst: [2, 3, 9, 7, 8]
* k: 5
*
* call:
*
* List<int> * pre = lst.prefix(5);
*
* after call:
* lst: []
* returned list: [2, 3, 9, 7, 8]
|