Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PreurediLista {
- public static SLLNode<Integer> getLastNode(SLL<Integer> list){
- SLLNode<Integer> tmp=list.getFirst();
- while(tmp.succ!=null){
- tmp=tmp.succ;
- }
- return tmp;
- }
- public static void preuredi(SLL<Integer> list){
- SLLNode<Integer> tmp=list.getFirst();
- int n=list.length()/2;
- while(n!=0){
- n--;
- SLLNode<Integer> last=getLastNode(list);
- list.insertAfter(last.element,tmp);
- list.delete(last);
- tmp=tmp.succ.succ;
- }
- System.out.println(list);
- }
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- int n=in.nextInt();
- SLL<Integer> list=new SLL<>();
- for(int i=0;i<n;i++){
- list.insertLast(in.nextInt());
- }
- preuredi(list);
- }
- }
Add Comment
Please, Sign In to add comment