Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.LinkedList;
- import java.util.Queue;
- import java.util.Scanner;
- import java.util.Stack;
- public class Program {
- static void bubbleSort(ArrayList<Packet> al) {
- int n = al.size();
- for (int i = 0; i < n-1; i++) {
- for (int j = 0; j < n-i-1; j++) {
- if (al.get(j).getNumber() > al.get(j + 1).getNumber()){
- // swap arr[j+1] and arr[j]
- Packet temp = al.get(j);
- al.set(j, al.get(j + 1));
- al.set(j + 1, temp);
- }
- }
- }
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- ArrayList<Packet> packets = new ArrayList<Packet>();
- System.out.print("Enter packets count: ");
- int n = Integer.parseInt(scan.nextLine());
- for (int i = 0; i < n; i++) {
- // read info, create object, add packets
- System.out.print("Read message: ");
- String msg = scan.nextLine();
- System.out.print("Read packet number: ");
- int num = Integer.parseInt(scan.nextLine());
- System.out.print("Read packet lose: ");
- double lose = Double.parseDouble(scan.nextLine());
- packets.add(new Packet(msg, num, lose));
- }
- bubbleSort(packets);
- /*for (int i = 0; i < packets.size(); i++) {
- System.out.print(packets.get(i));
- }*/
- System.out.println("Message: ");
- for (Packet p : packets) {
- if (p.getLosses() >= 0.5) {
- System.out.print(p);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement