Hi all
Am trying to Truncate the end of a linear list in java. so that:
// reduce the size of the list to s by removing all elements
// with indices greater or equal to s; return the number of removed
// elements;
// for example, if the list is [d, a, b, c, g, a], then truncateEnd(4)
// should change it to [d, a, b, c] and return 2;
// don’t do anything (and return 0), if the size of the list
// isn’t greater then s
public int truncateEnd(int s) {
// there is a method called remove() which takes as parameters specific index of the list and removes
// that! there is also a method called indexOf() that returns the specific index number of a given element
}
I have tried a few things but got no where! I tried a for loop but then realised that every time it goes the round the index of the specific elements are moving down one!
Any help would be much appreciated!!
ps the listed is manually implemented so its not an Array list or anything like that!