Martina312

Аритметичка средина

Feb 10th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. //Помеѓу секој пар 2 броја да се внесе нивната аритметичка средина
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class AritmetickaSredina {
  6.     public static void transform(SLL<Integer> list){
  7.         SLLNode<Integer> tmp=list.getFirst();
  8.         SLLNode<Integer> next;
  9.  
  10.         while (tmp!=null){
  11.             next=tmp.succ;
  12.             if(next==null){
  13.                 break;
  14.             }
  15.             int el=(tmp.element+next.element)/2;
  16.             tmp=next.succ;
  17.             list.insertBefore(el,next);
  18.         }
  19.         System.out.println(list);
  20.     }
  21.     public static void main(String[] args) {
  22.         Scanner in=new Scanner(System.in);
  23.         int n=in.nextInt();
  24.  
  25.         SLL<Integer> list=new SLL<>();
  26.         for(int i=0;i<n;i++){
  27.             list.insertLast(in.nextInt());
  28.         }
  29.         transform(list);
  30.     }
  31. }
Add Comment
Please, Sign In to add comment