void pushBook(BookStack *bkStack, BookNode *bkNode)
{
if(isEmpty(bkStack))
{
bkStack->lastNode = bkNode;
bkStack->lastNode->previousNode = NULL;
}
else
{
bkStack->lastNode->previousNode = bkStack->lastNode;
bkStack->lastNode = bkNode;
}
}
BookNode *popBook(BookStack *bkStack)
{
BookNode *temp = new BookNode;
if(isEmpty(bkStack))
{
temp = bkStack->lastNode;
return temp;
}
else if(bkStack->lastNode->previousNode == NULL)
{
temp = bkStack->lastNode;
bkStack->lastNode = NULL;
return temp;
}else
{
temp = bkStack->lastNode->previousNode;
bkStack->lastNode->previousNode = NULL;
bkStack->lastNode = temp;
return temp;
}
}
void displayStackElements(BookStack *bkStack)
{
BookNode *nodePtr = new BookNode;
nodePtr = bkStack->lastNode;
if(isEmpty(bkStack))
{
cout << "Book stack is empty." << endl;
}
else
{
while(nodePtr != NULL)
{
cout << "
Book Name: " << nodePtr->bk.name << endl;
cout << "Author Name: " << nodePtr->bk.authorName << endl;
cout << "Page Numbers: " << nodePtr->bk.pagesNumber << endl;
cout << "ISBN: " << nodePtr->bk.isbn << endl;
cout << endl;
nodePtr = bkStack->lastNode->previousNode;
}
}
}
bool isEmpty(BookStack *bkStack)
{
bool status;
if(bkStack->lastNode == NULL)
status = true;
else
status = false;
return status;
}
void addBook(BookStack *bkStack)
{
BookNode *bkNode = new BookNode;
cout << "
Enter the book name: ";
getline(cin, bkNode->bk.name);
cout << "Enter the Author's Name: ";
getline(cin, bkNode->bk.authorName);
cout << "Enter the ISBN: ";
cin >> bkNode->bk.isbn;
cout << "Enter the page numbers: ";
cin >> bkNode->bk.pagesNumber;
pushBook(bkStack, bkNode);
}
void removeBook(BookStack *bkStack)
{
BookNode *removedNode = new BookNode;
removedNode = popBook(bkStack);
if(removedNode == NULL)
{
cout << "
No books to remove." << endl;
}else
{
cout << endl << removedNode->bk.name << " was removed." << endl;
}
}
int pagesNumbering(int n)
{
int number_of_digits = 0;
for(int i = 1; i <= n; i *= 10)
number_of_digits += (n - i + 1);
return number_of_digits;
} // => tiến code