Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class RasteckaPodniza {
- public static void find(SLL<Integer> list){
- SLLNode<Integer> tmp=list.getFirst();
- SLLNode<Integer> tmp2;
- SLLNode<Integer> first=null;
- SLLNode<Integer> last=null;
- SLLNode<Integer> defFirst=null;
- SLLNode<Integer> defLast=null;
- int count=1;
- int max=0;
- boolean firstTry=false;
- while (tmp!=null){
- tmp2=tmp.succ;
- while (tmp2!=null){
- if(tmp.element<tmp2.element){
- count++;
- if(!firstTry){
- first=tmp;
- firstTry=true;
- }
- tmp=tmp.succ;
- if(tmp2.succ==null){
- last=tmp2;
- break;
- }
- if(tmp2.succ.element<tmp.element){
- last=tmp2;
- break;
- }
- tmp2=tmp2.succ;
- }
- else{
- break;
- }
- }
- if(count>max){
- max=count;
- defFirst=first;
- defLast=last;
- }
- tmp=tmp.succ;
- firstTry=false;
- count=1;
- }
- while (defFirst!=defLast.succ){
- System.out.print(defFirst.element+" ");
- defFirst=defFirst.succ;
- }
- System.out.println("broj na elementi: "+max);
- }
- 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());
- }
- find(list);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement