Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Prosekche;
- import java.util.Scanner;
- public class Prosek {
- public static void pecati(SLL<Integer> list)
- {
- SLLNode<Integer> i = list.getFirst();
- while(i!=null)
- {
- System.out.println(i.element + " ");
- i = i.succ;
- }
- }
- public static int prosek(SLL<Integer> list)
- {
- SLLNode<Integer> tmp = list.getFirst();
- int suma=0;
- int counter=0;
- while(tmp!=null)
- {
- suma+=tmp.element;
- tmp = tmp.succ;
- counter++;
- }
- return suma/counter;
- }
- public static SLL<Integer> pomali(SLL<Integer> list)
- {
- int prosek = prosek(list);
- SLLNode<Integer> tmp = list.getFirst();
- while(tmp!=null)
- {
- if(tmp.element < prosek)
- {
- list.insertLast(tmp.element);
- }
- tmp = tmp.succ;
- }
- return list;
- }
- public static SLL<Integer> pogolemi(SLL<Integer> list)
- {
- int prosek = prosek(list);
- SLLNode<Integer> tmp = list.getFirst();
- while(tmp!=null)
- {
- if(tmp.element>prosek)
- {
- list.insertLast(tmp.element);
- }
- tmp = tmp.succ;
- }
- return list;
- }
- public static void main(String[] args) {
- SLL<Integer> list = new SLL<Integer>();
- Scanner s = new Scanner(System.in);
- int n = s.nextInt();
- for(int i=0; i<n; i++)
- {
- list.insertLast(s.nextInt());
- }
- SLL<Integer> pomali = pomali(list);
- SLL<Integer> pogolemi = pogolemi(list);
- pecati(pomali);
- System.out.println();
- pecati(pogolemi);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement