Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SumaNaPrethodni {
- public static void transform(SLL<Integer> list){
- SLLNode<Integer> tmp=list.getFirst();
- boolean done=false;
- while (tmp!=null){
- int n=tmp.element;
- int sum=0;
- while (n!=0){
- n--;
- sum+=tmp.element;
- tmp=tmp.succ;
- if(tmp==null && n!=0){
- done=true;
- break;
- }
- if(tmp==null && n==0) break; // ova vazhi samo ako za poslednite sakamo da se izracuna vrednosta
- }
- if(done)
- break;
- list.insertBefore(sum,tmp);
- }
- 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());
- }
- transform(list);
- }
- }
Add Comment
Please, Sign In to add comment