У меня проблема с алгоритмом на Java. Этот алгоритм должен удалить элементы из списка, но только один раз (первый элемент). Я попробовал это, я скомпилировать хорошо, но проблемы, когда я запустить его ...Элементы удаления элементов PositionList
/**
* Returns in "list" the previous content of "list" after removing "subList" if it is present in "list"
*
* @param list (input/output) The list where search and remove the first occurrence of "subList"
* @param subList (input) The sub list to search within "list"
*/
public void removeSubList(PositionList<E> list,PositionList<E> subList) {
Position<E> cursor1 = list.first();
Position<E> cursor2 = subList.first();
while(cursor1 != null && cursor2 != null)
if(cursor1.element()==cursor2.element()){
Position<E> borrar = cursor1;
cursor1=list.next(cursor1);
cursor2=list.next(cursor2);
list.remove(borrar);
}
}
Это то, что я хочу на выходе консоли:
removeSubList ([3,2,3,4,5 , 3], [3]) [2,3,4,5,3]
removeSubList ([2,3,4,5,3,4], [3,4]) ----- ---> [2,5,3,4]
removeSubList ([3,2,3,4,7], [3,7]) --------> [3,2] , 3,4,7]
удалятьS ubList ([3,2,3,4,5,3], []) --------> [3,2,3,4,5,3]
removeSubList ([], [3,7]) --------> []
removeSubList (нуль, [3,7]) --------> нулевой
removeSubList ([3, 2,3,4,5,3], null) --------> [3,2,3,4,5,3]
Удалить только первое.
Спасибо за помощь.
Какие проблемы? Объясните пожалуйста: – Alboz