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;
- boolean element;
- public SLLNode(int id,int plata, SLLNode succ) {
- this.id = id;
- this.plata=plata;
- this.succ = succ;
- }
- }
- class SLL {
- private SLLNode first;
- private Object tmp;
- 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,SLL lista1) {
- // Vasiot kod tuka
- SLL lista3 = new SLL();
- SLLNode poc = lista1.getFirst();
- while(poc!=null){
- if(poc.plata >= iznos){
- lista3.insertLast(poc.id,poc.plata);
- poc=poc.succ;
- //lista3.insertLast(poc.succ);
- }
- else{
- poc=poc.succ;
- }
- }
- if(lista3.getFirst()==null){
- System.out.println("nema");
- }
- return lista3;
- }
- public SLL sortiraj_opagacki(SLL lista1) {
- // Vasiot kod tuka
- SLL lista = new SLL();
- SLLNode tmp = lista1.getFirst();
- SLLNode min;
- while(lista1.getFirst()!=null){
- tmp=min=lista1.getFirst();
- while(tmp!=null){
- if(tmp.id > min.id){
- min=tmp;
- }
- else {
- tmp=tmp.succ;
- // lista.insertLast(tmp.succ.id,tmp.succ.plata);
- }
- }
- lista.insertLast(min.id,min.plata);
- delete(min);
- }
- return lista;
- }
- public void pecati (SLL lista)
- {
- SLLNode p=lista.first;
- while(p!=null)
- {
- System.out.println(p.id+" "+p.plata);
- p=p.succ;
- }
- }
- private void insertLast(SLLNode succ) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- private void delete(SLLNode min) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- }
- 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),lista1);
- if(lista1!=null)
- {
- lista1=lista1.sortiraj_opagacki(lista1);
- lista1.pecati(lista1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement