I'm going to use the find method again. I need to find the
index of the person I want to move. In this example it would
be four. Then I need to remove them from that spot, so
that I won't have two copies of that person in the list. And
then the induces would change accordingly. Then once I've removed them, then
I want to add them at the front. I'm going to use add
instead of set, because I don't wipe to away the zeroth one,
I just want to move everybody down. So now this will be zero,
this will be one, two, three, four, five. In BlueJ that would look like,
get the Old Index, by finding the Person. And then if that Person is already
a friend we remove them from their old position and insert them into the
zeroth spot. If they're not already a friend, then we don't have to do anything.
Voy a utilizar el método find de nuevo. Tengo que encontrar el
índice de la persona que quiero eliminar. En este ejemplo
sería 4. Ahora tengo que sacarlos de ese lugar, para
no tener dos copias de esa persona en la lista. Y
entonces los indices cambiarían en consecuencia. Luego, una vez que los he quitado, ahora
quiero añadirlos al frente. Voy a usar add
en lugar de set porque no quiero borrar al amigo cero,
sólo quiero mover a todos hacia abajo. Así que ahora este va a ser cero,
este será uno, dos, tres, cuatro, cinco. En BlueJ, eso se vería como
obtener el índice antiguo mediante la búsqueda de una persona. Y luego, si esa persona ya es
un amigo, lo eliminamos de su antigua posición y lo insertamos en el
punto cero. Si aún no es un amigo, entonces no tenemos que hacer nada.
Je vais utiliser la méthode
Find à nouveau.
Je dois de trouver l'index de
la personne que je veux déplacer.
Dans cet exemple, ce serait 4.
Ensuite, je dois les retirer
de cet endroit,
afin que je n'aie pas deux copies
de cette personne dans la liste.
Et les indices changeraient
en conséquence.
Une fois que je les ai retirées,
je veux les mettre à l'avant.
Je vais utiliser add au lieu de set,
parce que je ne veux pas effacer le 0ième,
je veux juste déplacer
tout vers le bas.
Alors maintenant ce sera 0,
ce sera 1, 2, 3, 4, 5.
Dans BlueJ cela ressemblerait à obtenir
l'ancien index en trouvant la personne.
Et puis, si cette Personne
est déjà un ami,
nous le retirons de son ancienne
position et l'insérons dans le point 0.
Si ce n'est pas déjà un ami,
alors nous n'avons rien à faire.
再びfindメソッドを使います 動かしたい人の
インデックスを探します この例だと4です
それをその場所から削除してその人が
リストで重複しないようにします
その結果変更されたインデックスを削除したら
それを先頭に追加します
setの代わりにaddを使います
ゼロの人を削除するのではなく
全員を動かしたいからです これがゼロになり
これが1、2、3、4、5となります
BlueJではこのようになります
人を探すことでOld Indexを得ます
その人がすでに友人なら
古い位置から削除しゼロ番目の位置に挿入します
もし友人でなければ何もしなくていいです
저는 find 메소드를 다시 사용하겠습니다. 제가 옮기고 싶어 하는
사람의 인덱스가 필요합니다. 이 예시에서는 4로
하겠습니다. 그렇다면 4번에 있는 요소를 지워야
중복이 발생하지 않게 됩니다. 이렇게 하면
나머지 인덱스들도 자동적으로 자리를 찾아갑니다. 인덱스들을
지운 후에, 그 인덱스들을 앞에다가 추가해야 합니다. 저는 set
대신에 add를 이용하겠습니다. 왜냐하면 0번째 인덱스를
없애고 싶어하는 게 아닙니다. 나머지 인덱스들을 뒤로 밀려나가게
하고 싶습니다. 이제 여긴 0이고, 여긴 1, 여긴 2, 여긴 3, ... Bluej에서는
Person을 찾은 결과를 oldIndex에 저장하고, person이 친구라면
전에 있던 위치에서 삭제하고 0번째 인덱스로
다시 추가합니다. 만약 친구가 아니라면 아무것도 하지 않습니다.