Advertisement
AnaGocevska

Untitled

Oct 20th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. package Listi;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Listi {
  6.    
  7.    
  8.     public static void pecati(Array<Double> niza)
  9.     {
  10.         for(int i=0; i<niza.getLength(); i++)
  11.         {
  12.             System.out.print(niza.get(i)+" ");
  13.         }
  14.     }
  15.    
  16.     public static void pecati(SLL<Double> list)
  17.     {
  18.         SLLNode<Double> tmp = list.getFirst();
  19.        
  20.         while(tmp.succ != null)
  21.         {
  22.             System.out.print(tmp.element + " ");
  23.             tmp = tmp.succ;
  24.         }
  25.         System.out.print(tmp.element);
  26.     }
  27.    
  28.     public static double maxElement(SLL<Double> list)
  29.     {
  30.         SLLNode<Double> tmp = list.getFirst();
  31.         double maxi = list.getFirst().element;
  32.        
  33.         while(tmp != null)
  34.         {
  35.             if(tmp.element.compareTo(maxi)==1)
  36.             {
  37.                 maxi = tmp.element;
  38.             }
  39.             tmp = tmp.succ;
  40.         }
  41.         return maxi;
  42.     }
  43.    
  44.     public static double aritmeticka(SLL<Double> list)
  45.     {
  46.         SLLNode<Double> tmp = list.getFirst();
  47.         double sum=0;
  48.        
  49.         while(tmp != null)
  50.         {
  51.             sum+=tmp.element;
  52.             tmp = tmp.succ;
  53.         }
  54.         int k = list.length();
  55.         double prosek = (double)sum/k;
  56.         return prosek;
  57.     }
  58.    
  59.     public static SLL<Double> duplicati(SLL<Double> list)
  60.     {
  61.         SLLNode<Double> i = list.getFirst();
  62.         SLLNode<Double> j = i.succ;
  63.        
  64.         while(i != null)
  65.         {
  66.             j = i.succ;
  67.             while(j != null)
  68.             {
  69.                 if(i.element.equals(j.element))
  70.                 {
  71.                     SLLNode<Double> tmp = j;
  72.                     list.delete(tmp);
  73.                 }
  74.                 j = j.succ;
  75.             }
  76.             i = i.succ;
  77.         }
  78.        
  79.         return list;
  80.     }
  81.    
  82.    
  83.     /*public static SLL<Double> sort(SLL<Double> list)
  84.     {
  85.         SLLNode<Double> i = list.getFirst();
  86.         SLLNode<Double> j = i.succ;
  87.        
  88.         while(i != null)
  89.         {
  90.             j = i.succ;
  91.             while(j != null)
  92.             {
  93.                 if(i.element.compareTo(j.element)==1)
  94.                 {
  95.                     SLLNode<Double> tmp = i.succ;
  96.                     i = tmp.succ;
  97.                     //j = 0
  98.                 }
  99.             }
  100.         }
  101.     }*/
  102.    
  103.     public static SLL<Double> transform (Array<Double> niza)
  104.     {
  105.         SLL<Double> list = new SLL<Double>();
  106.         for(int i=0; i<niza.getLength(); i++)
  107.         {
  108.             list.insertLast(niza.get(i));
  109.         }
  110.         return list;
  111.     }
  112.            
  113.            
  114.     public static void main (String [] args)
  115.     {
  116.         SLL<Double> list = new SLL<Double>();
  117.         Scanner s = new Scanner(System.in);
  118.        
  119.        
  120.         int n;
  121.         n = s.nextInt();
  122.        
  123.         Array<Double> niza;
  124.         niza = new Array<Double>(n);
  125.        
  126.         for(int i=0; i<n; i++)
  127.         {
  128.             niza.set(i, s.nextDouble());
  129.         }
  130.        
  131.         Array<Double> transNiza = transform(list);
  132.         SLL<Double> transLista = transform(niza);
  133.        
  134.         for(int i=0; i<n; i++)
  135.         {
  136.             list.insertLast(s.nextDouble());
  137.         }
  138.            
  139.     }
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement