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) {
- // Vasiot kod tuka
- /* SLL rezultat=new SLL();
- SLLNode tmp=first;
- while(tmp!=null){
- if(tmp.plata>=iznos){
- rezultat.insertLast(tmp.id,tmp.plata);
- }
- tmp=tmp.succ;
- }
- return rezultat;*/
- SLLNode tmp=this.first;
- while(tmp!=null){
- if(tmp.plata<iznos){
- if(tmp==first){
- tmp=tmp.succ;
- first=first.succ;
- }
- else if(tmp.succ==null){
- SLLNode tmp2=first;
- while(tmp2.succ!=tmp){
- tmp2=tmp2.succ;
- }
- if(tmp2.succ==tmp) {
- tmp2.succ = null;
- tmp = null;
- }
- }
- else{
- SLLNode tmp2=first;
- while(tmp2.succ!=tmp){
- tmp2=tmp2.succ;
- }
- if(tmp2.succ==tmp){
- tmp2.succ=tmp.succ;
- tmp=tmp2.succ;
- }
- }
- }
- else{
- tmp=tmp.succ;
- }
- }
- return this;
- }
- public SLL sortiraj_opagacki() {
- // Vasiot kod tuka
- SLL rezultat=new SLL();
- rezultat=this;
- SLLNode tmp=rezultat.first;
- SLLNode tmp2;
- while(tmp!=null){
- tmp2=tmp.succ;
- while(tmp2!=null){
- if(tmp.id <= tmp2.id){
- int tmpP=tmp.plata;
- tmp.plata=tmp2.plata;
- tmp2.plata=tmpP;
- int tmpI=tmp.id;
- tmp.id=tmp2.id;
- tmp2.id=tmpI;
- }
- tmp2=tmp2.succ;
- }
- tmp=tmp.succ;
- }
- return rezultat;
- }
- 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.getFirst()!=null)
- {
- lista1=lista1.sortiraj_opagacki();
- lista1.pecati(lista1);
- }
- else{
- System.out.println("nema");
- }
- }
- }
Add Comment
Please, Sign In to add comment