Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 2021 prv kolokvium - termin 2
- import java.util.Scanner;
- class Student {
- private int indeks;
- private String ime;
- private int poeni;
- public Student(int indeks, String ime, int poeni) {
- this.indeks = indeks;
- this.ime = ime;
- this.poeni = poeni;
- }
- public int getIndeks() {
- return indeks;
- }
- public void setIndeks(int indeks) {
- this.indeks = indeks;
- }
- public String getIme() {
- return ime;
- }
- public void setIme(String ime) {
- this.ime = ime;
- }
- public int getPoeni() {
- return poeni;
- }
- public void setPoeni(int poeni) {
- this.poeni = poeni;
- }
- @Override
- public String toString() {
- return String.valueOf(ime);
- }
- }
- class SLLNode<E> {
- protected E element;
- protected SLLNode<E> succ;
- public SLLNode(E elem, SLLNode<E> succ) {
- this.element = elem;
- this.succ = succ;
- }
- @Override
- public String toString() {
- return element.toString();
- }
- }
- class SLL<E> {
- private SLLNode<E> first;
- public SLL() {
- this.first = null;
- }
- public void deleteList() {
- first = null;
- }
- public int length() {
- int ret;
- if (first != null) {
- SLLNode<E> tmp = first;
- ret = 1;
- while (tmp.succ != null) {
- tmp = tmp.succ;
- ret++;
- }
- return ret;
- } else
- return 0;
- }
- @Override
- public String toString() {
- String ret = new String();
- if (first != null) {
- SLLNode<E> tmp = first;
- ret += tmp;
- while (tmp.succ != null) {
- tmp = tmp.succ;
- ret += " " + tmp;
- }
- } else
- ret = "Prazna lista!!!";
- return ret;
- }
- public void insertFirst(E o) {
- SLLNode<E> ins = new SLLNode<E>(o, first);
- first = ins;
- }
- public void insertAfter(E o, SLLNode<E> node) {
- if (node != null) {
- SLLNode<E> ins = new SLLNode<E>(o, node.succ);
- node.succ = ins;
- } else {
- System.out.println("Dadenot jazol e null");
- }
- }
- public void insertBefore(E o, SLLNode<E> before) {
- if (first != null) {
- SLLNode<E> tmp = first;
- if (first == before) {
- this.insertFirst(o);
- return;
- }
- while (tmp.succ != before)
- tmp = tmp.succ;
- if (tmp.succ == before) {
- SLLNode<E> ins = new SLLNode<E>(o, before);
- tmp.succ = ins;
- } else {
- System.out.println("Elementot ne postoi vo listata");
- }
- } else {
- System.out.println("Listata e prazna");
- }
- }
- public void insertLast(E o) {
- if (first != null) {
- SLLNode<E> tmp = first;
- while (tmp.succ != null)
- tmp = tmp.succ;
- SLLNode<E> ins = new SLLNode<E>(o, null);
- tmp.succ = ins;
- } else {
- insertFirst(o);
- }
- }
- public E deleteFirst() {
- if (first != null) {
- SLLNode<E> tmp = first;
- first = first.succ;
- return tmp.element;
- } else {
- System.out.println("Listata e prazna");
- return null;
- }
- }
- public E delete(SLLNode<E> node) {
- if (first != null) {
- SLLNode<E> tmp = first;
- if (first == node) {
- return this.deleteFirst();
- }
- while (tmp.succ != node && tmp.succ.succ != null)
- tmp = tmp.succ;
- if (tmp.succ == node) {
- tmp.succ = tmp.succ.succ;
- return node.element;
- } else {
- System.out.println("Elementot ne postoi vo listata");
- return null;
- }
- } else {
- System.out.println("Listata e prazna");
- return null;
- }
- }
- public SLLNode<E> getFirst() {
- return first;
- }
- public SLLNode<E> find(E o) {
- if (first != null) {
- SLLNode<E> tmp = first;
- while (tmp.element != o && tmp.succ != null)
- tmp = tmp.succ;
- if (tmp.element == o) {
- return tmp;
- } else {
- System.out.println("Elementot ne postoi vo listata");
- }
- } else {
- System.out.println("Listata e prazna");
- }
- return first;
- }
- }
- public class APSCourse {
- public static void remove_student(SLL<Student> aps_course){
- SLLNode<Student> temp= aps_course.getFirst();
- int least_poeni= temp.element.getPoeni();
- int worst_student= temp.element.getIndeks();
- temp=temp.succ;
- while(temp!=null){
- if(temp.element.getPoeni()<least_poeni){
- least_poeni=temp.element.getPoeni();
- worst_student= temp.element.getIndeks();
- }
- temp=temp.succ;
- }
- temp= aps_course.getFirst();
- while(true){
- if(temp.element.getIndeks()==worst_student){
- aps_course.delete(temp);
- break;
- }
- temp=temp.succ;
- }
- }
- public static void main(String[] args) {
- Scanner input= new Scanner(System.in);
- int n= Integer.parseInt(input.nextLine());
- SLL<Student> aps_course= new SLL<Student>();
- for(int i=0;i<n;i++){
- String[] student= input.nextLine().split("\\s+");
- aps_course.insertLast(new Student(Integer.parseInt(student[0]),student[1],Integer.parseInt(student[2])));
- }
- remove_student(aps_course);
- System.out.println(aps_course);
- }
- }
- /*
- 6
- 201182 KingDzoce 77
- 201117 Adminot 89
- 201155 TOMI 56
- 211196 Nono 0
- 201146 SaveAFile 51
- 201038 OG 107
- KingDzoce Adminot TOMI SaveAFile OG
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement