Advertisement
Martina312

Rastecka Podniza

Feb 12th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class RasteckaPodniza {
  4.     public static void find(SLL<Integer> list){
  5.         SLLNode<Integer> tmp=list.getFirst();
  6.         SLLNode<Integer> tmp2;
  7.         SLLNode<Integer> first=null;
  8.         SLLNode<Integer> last=null;
  9.         SLLNode<Integer> defFirst=null;
  10.         SLLNode<Integer> defLast=null;
  11.  
  12.         int count=1;
  13.         int max=0;
  14.         boolean firstTry=false;
  15.         while (tmp!=null){
  16.             tmp2=tmp.succ;
  17.  
  18.             while (tmp2!=null){
  19.                 if(tmp.element<tmp2.element){
  20.                     count++;
  21.                     if(!firstTry){
  22.                         first=tmp;
  23.                         firstTry=true;
  24.                     }
  25.                     tmp=tmp.succ;
  26.                     if(tmp2.succ==null){
  27.                         last=tmp2;
  28.                         break;
  29.                     }
  30.                     if(tmp2.succ.element<tmp.element){
  31.                         last=tmp2;
  32.                         break;
  33.                     }
  34.                     tmp2=tmp2.succ;
  35.                 }
  36.                 else{
  37.                     break;
  38.                 }
  39.             }
  40.             if(count>max){
  41.                 max=count;
  42.                 defFirst=first;
  43.                 defLast=last;
  44.             }
  45.             tmp=tmp.succ;
  46.             firstTry=false;
  47.             count=1;
  48.         }
  49.  
  50.         while (defFirst!=defLast.succ){
  51.             System.out.print(defFirst.element+" ");
  52.             defFirst=defFirst.succ;
  53.         }
  54.         System.out.println("broj na elementi: "+max);
  55.     }
  56.     public static void main(String[] args) {
  57.         Scanner in=new Scanner(System.in);
  58.  
  59.         int n=in.nextInt();
  60.         SLL<Integer> list=new SLL<>();
  61.         for(int i=0;i<n;i++){
  62.             list.insertLast(in.nextInt());
  63.         }
  64.         find(list);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement