Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import java.util.Scanner; class DLLNode
{ protected E element; protected DLLNode
pred, succ; public DLLNode(E elem, DLLNode
pred, DLLNode
succ) { this.element = elem; this.pred = pred; this.succ = succ; } @Override public String toString() { return "<-" + element.toString() + "->"; } } class DLL
{ private DLLNode
first, last; public DLL() { // Construct an empty SLL this.first = null; this.last = null; } public void deleteList() { first = null; last = null; } public int length() { int ret; if (first != null) { DLLNode
tmp = first; ret = 1; while (tmp.succ != null) { tmp = tmp.succ; ret++; } return ret; } else return 0; } public void insertFirst(E o) { DLLNode
ins = new DLLNode
(o, null, first); if (first == null) last = ins; else first.pred = ins; first = ins; } public void insertLast(E o) { if (first == null) insertFirst(o); else { DLLNode
ins = new DLLNode
(o, last, null); last.succ = ins; last = ins; } } public void insertAfter(E o, DLLNode
after) { if (after == last) { insertLast(o); return; } DLLNode
ins = new DLLNode
(o, after, after.succ); after.succ.pred = ins; after.succ = ins; } public void insertBefore(E o, DLLNode
before) { if (before == first) { insertFirst(o); return; } DLLNode
ins = new DLLNode
(o, before.pred, before); before.pred.succ = ins; before.pred = ins; } public E deleteFirst() { if (first != null) { DLLNode
tmp = first; first = first.succ; if (first != null) first.pred = null; if (first == null) last = null; return tmp.element; } else return null; } public E deleteLast() { if (first != null) { if (first.succ == null) return deleteFirst(); else { DLLNode
tmp = last; last = last.pred; last.succ = null; return tmp.element; } } // else throw Exception return null; } @Override public String toString() { String ret = new String(); if (first != null) { DLLNode
tmp = first; ret += tmp + "<->"; while (tmp.succ != null) { tmp = tmp.succ; ret += tmp + "<->"; } } else ret = "Prazna lista!!!"; return ret; } public DLLNode
getFirst() { return first; } public DLLNode
getLast() { return last; } } public class PalindromeDLL { public static int isItPalindrome(DLL
list){ DLLNode
first = list.getFirst(); DLLNode
last = list.getLast(); while(first.element == last.element) { first = first.succ; last = last.pred; if(first == null) { return 1; } } return -1; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); DLL
list = new DLL
(); for (int i = 0; i < n; i++) { list.insertLast(in.nextInt()); } in.close(); System.out.println(isItPalindrome(list)); } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)