Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package vezbanje_za_prv_kolokvium;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- /**
- *
- * @author Damjan
- */
- public class PrevrtiLista {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- DLL<Integer> lista = new DLL<>();
- BufferedReader stdin = new BufferedReader(new InputStreamReader(
- System.in));
- String s = stdin.readLine();
- int N = Integer.parseInt(s);
- s = stdin.readLine();
- String[] pomniza = s.split(" ");
- for (int i = 0; i < N; i++) {
- lista.insertLast(Integer.parseInt(pomniza[i]));
- }
- DLL<Integer> prevrtena = prevrti(lista);
- DLLNode<Integer> jazol = prevrtena.getFirst();
- while (jazol != null) {
- System.out.print(jazol.element);
- if (jazol.succ != null) {
- System.out.print(" ");
- }
- jazol = jazol.succ;
- }
- }
- static DLL<Integer> prevrti(DLL<Integer> lista) {
- DLLNode<Integer> jazol = lista.getLast();
- DLL<Integer> rezultat = new DLL<>();
- while (jazol != null) {
- if (jazol.element % 2 == 0) {
- rezultat.insertLast(jazol.element);
- jazol = jazol.pred;
- } else {
- rezultat.insertLast(jazol.element);
- jazol = jazol.pred;
- }
- }
- return rezultat;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement