#include <stdio.h>
#include <stdlib.h>

/* ---------- STRUCTURES ---------- */
struct header {
    int numBooks;
    struct Node *next;
};

typedef struct Node {
    int BookId;
    struct Node *next;
} Node;

/* ---------- GLOBALS ---------- */
struct header *head = NULL;
Node *first = NULL;

/* ---------- INITIALIZATION ---------- */
void init() {
    head = malloc(sizeof(struct header));
    head->numBooks = 0;
    head->next = NULL;
    first = NULL;
}

/* ---------- RETURN BOOK ---------- */
void returnBook(int ID) {
    Node *newBook = malloc(sizeof(Node));
    newBook->BookId = ID;
    newBook->next = first;

    first = newBook;
    head->next = first;
    head->numBooks++;
}

/* ---------- SEARCH / DISPLAY ---------- */
void search() {
    Node *temp = first;

    while (temp != NULL) {
        printf("Book no: %d -> ", temp->BookId);
        temp = temp->next;
    }
    printf("NULL\n");
}

/* ---------- SHELVE BOOK ---------- */
void shelve() {
    if (first == NULL) {
        printf("No books available\n");
        return;
    }

    Node *temp = first;
    first = first->next;
    head->next = first;

    free(temp);
    head->numBooks--;
}

/* ---------- MAIN ---------- */
int main() {
    init();

    returnBook(1);
    returnBook(2);
    search();

    shelve();
    search();

    shelve();
    search();

    returnBook(3);
    search();

    printf("Total books: %d\n", head->numBooks);
    return 0;
}