#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
int bookId;
struct Node *next;
} Node;
struct header {
int numBooks;
Node *next;
};
struct header *head = NULL;
void BookReturn() {
int ID;
printf("Enter Book ID: ");
scanf("%d", &ID);
Node *newBook = malloc(sizeof(Node));
newBook->bookId = ID;
newBook->next = head->next;
head->next = newBook;
head->numBooks++;
printf("Book returned successfully.\n");
}
void searchBook() {
int ID;
printf("Enter Book ID to search: ");
scanf("%d", &ID);
Node *temp = head->next;
while (temp != NULL) {
if (temp->bookId == ID) {
printf("Book found.\n");
return;
}
temp = temp->next;
}
printf("Book not found.\n");
}
void shelveBook() {
if (head->next == NULL) {
printf("No books to shelve.\n");
return;
}
Node *temp = head->next;
head->next = temp->next;
free(temp);
head->numBooks--;
printf("Book shelved successfully.\n");
}
int main() {
head = malloc(sizeof(struct header));
head->numBooks = 0;
head->next = NULL;
int choice;
int stop = 0;
while (!stop) {
printf("\n1. Return a Book\n");
printf("2. Search for a Book\n");
printf("3. Take a Book for Shelving\n");
printf("4. Exit\n");
printf("Enter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
BookReturn();
break;
case 2:
searchBook();
break;
case 3:
shelveBook();
break;
case 4:
stop = 1;
break;
default:
printf("Invalid choice\n");
}
printf("Total books: %d\n", head->numBooks);
}
return 0;
}