class Node {
String title;
double price;
String edition;
int pages;
Node next;
public Node(String title, double price, String edition, int pages) {
[Link] = title;
[Link] = price;
[Link] = edition;
[Link] = pages;
[Link] = null;
class Stack {
Node top;
public Stack() {
[Link] = null;
public void push(Node book) {
if (top == null) {
top = book;
} else {
[Link] = top;
top = book;
}
public Node pop() {
if (top == null) {
return null;
} else {
Node poppedBook = top;
top = [Link];
[Link] = null;
return poppedBook;
public Node peek() {
return top;
public class Main {
public static void main(String[] args) {
Stack stack = new Stack();
// Push 5 books into the stack
[Link](new Node("Book 1", 10.0, "First Edition", 100));
[Link](new Node("Book 2", 15.0, "Second Edition", 200));
[Link](new Node("Book 3", 20.0, "Third Edition", 150));
[Link](new Node("Book 4", 12.0, "Fourth Edition", 180));
[Link](new Node("Book 5", 18.0, "Fifth Edition", 250));
// Find the top element of the stack
Node topBook = [Link]();
if (topBook != null) {
[Link]("The top book in the stack is: " + [Link]);
} else {
[Link]("The stack is empty.");
// Pop 2 books from the stack
Node poppedBook1 = [Link]();
Node poppedBook2 = [Link]();
// Display the remaining books in the stack
Node currentBook = [Link]();
[Link]("The remaining books in the stack are:");
while (currentBook != null) {
[Link]([Link]);
currentBook = [Link];