Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- class SLLNode {
- protected int id;
- protected int plata;
- protected SLLNode succ;
- public SLLNode(int id,int plata, SLLNode succ) {
- this.id = id;
- this.plata=plata;
- this.succ = succ;
- }
- }
- class SLL {
- private SLLNode first;
- public SLL() {
- // Construct an empty SLL
- this.first = null;
- }
- public void deleteList() {
- first = null;
- }
- public int length() {
- int ret;
- if (first != null) {
- SLLNode tmp = first;
- ret = 1;
- while (tmp.succ != null) {
- tmp = tmp.succ;
- ret++;
- }
- return ret;
- } else
- return 0;
- }
- public void insertFirst(int id, int plata) {
- SLLNode ins = new SLLNode(id,plata, first);
- first = ins;
- }
- public void insertLast(int id,int plata) {
- if (first != null) {
- SLLNode tmp = first;
- while (tmp.succ != null)
- tmp = tmp.succ;
- SLLNode ins = new SLLNode(id, plata, null);
- tmp.succ = ins;
- } else {
- insertFirst(id,plata);
- }
- }
- public SLLNode getFirst() {
- return first;
- }
- public SLL brisi_pomali_od(int iznos) {
- SLLNode tmp = getFirst();
- SLL novo = new SLL();
- while (tmp != null) {
- if (tmp.plata >= iznos)
- novo.insertLast(tmp.id, tmp.plata);
- tmp = tmp.succ;
- }
- if(novo.length() ==0) System.out.println("nema");
- return novo;
- }
- public SLL sortiraj_opagacki() {
- SLLNode temp = getFirst();// node temp = head;
- while (temp!=null) { // Traverse the List
- SLLNode min = temp; // node min = temp;
- SLLNode r = temp.succ;// node r = temp.next;
- // Traverse the unsorted sublist
- while (r!=null) {
- if(min.id < r.id) // if (min.data > r.data)
- min = r;
- r = r.succ; //r = r.next;
- }
- // Swap Data
- int x = temp.id; //int x = temp.data;
- temp.id = min.id; //temp.data = min.data;
- min.id = x; //min.data = x;
- x = temp.plata;
- temp.plata = min.plata;
- min.plata = x;
- temp = temp.succ; //temp = temp.next;
- }
- return this;
- }
- public void pecati (SLL lista)
- {
- SLLNode p=lista.first;
- while(p!=null)
- {
- System.out.println(p.id+" "+p.plata);
- p=p.succ;
- }
- }
- }
- public class SLLKompanija {
- public static void main(String[] args) throws IOException {
- SLL lista1 = new SLL();
- BufferedReader stdin = new BufferedReader(new InputStreamReader(
- System.in));
- String s = stdin.readLine();
- int N = Integer.parseInt(s);
- for (int i = 0; i < N; i++) {
- s=stdin.readLine();
- String s1=stdin.readLine();
- lista1.insertLast(Integer.parseInt(s),Integer.parseInt(s1));
- }
- s = stdin.readLine();
- lista1=lista1.brisi_pomali_od(Integer.parseInt(s));
- if(lista1!=null)
- {
- lista1=lista1.sortiraj_opagacki();
- lista1.pecati(lista1);
- }
- }
- }
- /*
- Податоците за плати на вработените во една компанија привремено се чуваат во еднострано поврзана листа.
- Во секој јазол од листата се чува единствен ID на вработениот и неговата плата. Потребно е да се отстранат
- сите вработени со помали плати од даден износ, а остатокот да се прикажат во опаѓачки редослед во однос на ID-то.
- Во првиот ред од влезот е даден бројот на вработени, потоа наизменично се дадени ID и плата за секој од вработените
- и во последниот ред е износот во однос на кој ќе се отстрануваат вработените. На излез се печати листа (ID, плата)
- во опаѓачки редослед според ID на секој од вработените.
- Доколку нема вработени со плата поголема од дадената да се испечати: nema
- Име на класата: SLLKompanija
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement