hey guys ! i am unable to understand how to implement the function insert at head and insert at tail ..
class Book {
public:
char * title;
float price;
// constructor for class Book
Book ()
{
char* title = new char[20];
strcpy(title,"untitled");
price = 0 ;
}
void SetPrice(float p)
{
price = p ;
}
float GetPrice ()
{
return price ;
}
void SetTitle (char ch[] )
{
strcpy(title,ch );
}
char GetTitle ()
{
return *title ;
}
~Book ()
{
delete[] title ;
}
};
class Node {
public:
Book s;
Node * next;
// constructor for class Node
Node ()
{
s.SetPrice(0);
s.GetPrice();
s.SetTitle("untitled");
s.GetTitle();
next = nullptr ;
}
void setNodeBook (Book b)
{
s.SetPrice(b.price);
s.SetTitle(b.title);
}
void setNodeNext(Node *n)
{
n = next ;
}
};
class List {
private:
Node * head;
Node * tail;
public:
// Add getters and setters here
List() // constructor for a list
{
head = nullptr ;
tail = nullptr ;
}
void SetHead (Node *h)
{
head = h ;
}
void SetTail (Node *t)
{
tail = t ;
}
Node* GetHead ()
{
return head ;
}
Node* GetTail ()
{
return tail ;
}
void InsertAtHead(Book s)
{
Node* n = new Node ;
if (n == nullptr )
{
cout << " out of memory " << endl;
exit(1);
}
else
{
head->s.SetPrice(s.price);
head->s.SetTitle(s.title);
n->next = head ;
}
}
void InsertAtTail(Book s)
{
Node* n = new Node ;
if (n == nullptr)
{
cout << " out of memory " << endl;
exit(1);
}
else
{
tail->s.SetPrice(s.price);
tail->s.SetTitle(s.title);
n->next = tail ;
}
}
Book RemoveFromHead()
{
}
Book RemoveFromTail();
Book ViewBookFromHead();
Book ViewBookFromTail();
void Print();
//Add Your function here
};