Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class RazigranaLista {
- public static void izbrishi(DLL<Character> list){
- DLLNode<Character> tmp;
- while(true) {
- tmp=list.getFirst();
- while (tmp != null) {
- tmp = tmp.succ;
- if (tmp == null)
- break;
- DLLNode<Character> kopija = tmp;
- list.delete(tmp);
- tmp = kopija.succ;
- }
- if (list.length() == 1) {
- System.out.println(list);
- return;
- }
- DLLNode<Character> tmp2 = list.getLast();
- while (tmp2 != null) {
- tmp2 = tmp2.pred;
- if (tmp2 == null)
- break;
- DLLNode<Character> kopija2 = tmp2;
- list.delete(tmp2);
- tmp2 = kopija2.pred;
- }
- if (list.length() == 1) {
- System.out.println(list);
- return;
- }
- }
- }
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- String line=in.nextLine();
- String[] parts=line.split(" ");
- DLL<Character> list=new DLL<>();
- for(int i=0;i<parts.length;i++){
- list.insertLast(parts[i].charAt(0));
- }
- izbrishi(list);
- }
- }
Add Comment
Please, Sign In to add comment