Create doubly linked list that has the following information about books: book_id, book_name, author_id, book_price. Sort list in ascending order by book_price using bubble sort algorithm. Delete all books with the smallest and the largest price.

How to modify the following program such that the sorting is done using bubble sort algorithm? Also, how to implement a function for deletion of all books with the smallest and the largest price (more books can have the same price)?

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

int deleteNodes(NODE **head,NODE **tail,float book_price);//deletes only the specified node

typedef struct
{
char book_id[8];
char book_title[21];
char author_id[10];
float book_price;
}BOOK;

typedef struct node
{
BOOK bk;
struct node *left,*right;
}NODE;

{
NODE *p,*q,*new_node=(NODE *)malloc(sizeof(NODE));
new_node->bk=*bk;
new_node->left=0;
new_node->right=0;

{
}
else if((*tail)->bk.book_price < bk->book_price)
{
new_node->left=*tail;
(*tail)->right=new_node;
*tail=new_node;
}
else
{
(p->right->bk.book_price < bk->book_price) && (q->bk.book_price > bk->book_price);
p=p->right,q=q->left);
if(q->bk.book_price > bk->book_price)
p=q;
new_node->right=p->right;
new_node->left=p;
p->right->left=new_node;
p->right=new_node;
}
}

{
BOOK bk;
return 0;
while((head->bk.book_price < bk.book_price) && (tail->bk.book_price > bk.book_price))
{
tail=tail->left;
}
return (head->bk.book_price == book_price) ? head : ((tail->bk.book_price == book_price) ? tail : 0 );
}

{
if(p == 0)
return 0;
else if(p == *head && p == *tail)
{
}
else if(p == *tail)
{
*tail=(*tail)->left;
(*tail)->right=0;
}
else
{
p->left->right=p->right;
p->right->left=p->left;
}
free(p);
return 1;
}

{
printf("Book ID: ");
scanf("%s",bk->book_id);
fflush(stdin);
printf("Book title: ");
gets(bk->book_title);
printf("Author ID: ");
scanf("%s",bk->author_id);
printf("Book price: ");
scanf("%f",&bk->book_price);
}

{
printf("BOOK_ID BOOK_TITLE           AUTHOR_ID BOOK_PRICE\n");
printf("------- -------------------- --------- ----------\n");
{
printf("%-7s %-20s %-9s %10.2f\n",
}
}

int main()
{
BOOK bk;
char option;
float book_price;

printf("Option 'A': add node to list.\n");
printf("Option 'D': delete node from list by book price.\n");
printf("Option 'P': print list.\n");
printf("Option 'S': search list.\n");
printf("Option '0': exit.\n");

while(1)
{
fflush(stdin);
printf("\nEnter option: ");
scanf("%c",&option);

if(option == 'A')
{
printf("Enter data: \n");
if(p)
p->bk=bk;
else
}

else if(option == 'D')
{
printf("Book price: ");
scanf("%f",&book_price);
printf("data about book with price %f is deleted.",book_price);
else printf("no data about book with price %f.",book_price);
}

else if(option == 'P')

else if(option == 'S')
{
printf("Book price: ");
scanf("%f",&book_price);
if(p)
printf("%s has a price %f.",p->bk.book_id,p->bk.book_price);
else
printf("no data about book with price %f",p->bk.book_price);
}

else if(option == '0')
{
printf("End.");
break;
}

else printf("Unknown option.\n");
}

return 0;
}
``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.