-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook1.java
49 lines (47 loc) · 1.26 KB
/
Book1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
class Book1 implements Comparable <Book1>{
int id;
String name,author,publisher;
int quality;
public Book1(int id, String name, String author, String publisher, int quantity){
this.id = id ;
this.name = name;
this.author = author;
this.publisher = publisher;
this.quantity = quantity;
}
public int compareTo(Book1 b){
if (id>b.id){
return 1;
}
else if(id<b.id){
return -1;
}
else{
return 0;
}
}
}
public class LinkedListExample {
public static void main(String [] agrs){
Queue<Book1> queue = new PriorityQueue<Book1>();
//Creating Books
Book1 b1=new Book1(121,"Let us C","Yashwant Kanetkar","BPB",8);
Book1 b2=new Book1(233,"Operating System","Galvin","Wiley",6);
Book1 b3=new Book1(101,"Data Communications & Networking","Forouzan","Mc Graw Hill",4);
//Adding Books to the queue
queue.add(b1);
queue.add(b2);
queue.add(b3);
System.out.println("Traversing the queue elements : ");
//Travesing
for(Book1 b: queue){
System.out.println(b.id+" "+b.name+" "+b.author+" "+b.publisher+" "+b.quantity);
queue.remove();
System.out.println("After removing one book record : ");
for(Book1 b:queue){
System.out.println(b.id+" "+b.name+" "+b.author+" "+b.publisher+" "+b.quantity);
}
}
}
}