Professional Documents
Culture Documents
Подели според просек
Подели според просек
, ..
,
.
(..
,
...).
,
.
( ),
( ) .
( Java): PodeliListaProsek
: 7
.
: ,
.
Input:
10
1 3 5 7 9
2 4 6 8 10
Output:
4 2 5 3 1
10 8 6 9 7
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
class DLLNode<E> {
protected E element;
protected DLLNode<E> pred, succ;
@Override
public String toString() {
return element.toString();
}
}
class DLL<E> {
private DLLNode<E> first, last;
public DLL() {
// Construct an empty SLL
this.first = null;
this.last = null;
}
public E deleteFirst() {
if (first != null) {
DLLNode<E> tmp = first;
first = first.succ;
if (first != null) first.pred = null;
if (first == null)
last = null;
return tmp.element;
} else
return null;
}
public E deleteLast() {
if (first != null) {
if (first.succ == null)
return deleteFirst();
else {
DLLNode<E> tmp = last;
last = last.pred;
last.succ = null;
return tmp.element;
}
}
// else throw Exception
return null;
}
@Override
public String toString() {
String ret = new String();
if (first != null) {
DLLNode<E> tmp = first;
ret += tmp+" " ;
while (tmp.succ != null) {
tmp = tmp.succ;
ret += tmp+" " ;
}
} else
ret = "Prazna lista!!!";
return ret;
}
return last;
}
}
}
int b = input.nextInt();
lista.insertLast(b);
}
int sum=0;
DLLNode<Integer> node = lista.getFirst();
while(node!=null)
{
sum+=node.element;
node=node.succ;
}
double prosek = sum/n;
node = lista.getLast();
while(node!=null)
{
if(node.element<=prosek)
{
pomali.insertLast(node.element);
}
else pogolemi.insertLast(node.element);
node=node.pred;
}
System.out.println(pomali.toString());
System.out.println(pogolemi.toString());