while (ptr != NULL && compare(x, (*ptr).data == GREATER))
registers an error that says
lab1.cpp no match for 'operator==' in 'ptr->node::data == GREATER'
I use dev c++ as my compiler
any help will be appreciated
Code:
#include <iostream>
#include <string>
using namespace std;
struct itemType
{
string author;
string title;
float price;
};
struct node
{
itemType data;
node *next;
};
class sortedList
{
private:
node *head;
public:
void add (itemType x);
sortedList ();
};
enum compType {LESSER, GREATER, EQUAL};
compType compare(itemType x, itemType y);
int main ()
{
typedef itemType book;
sortedList shelf;
book a,b,c,d;
a.author = "J.K Rowling";
a.title = "Harry Potter";
a.price = 19.99;
b.author = "C.S Lewis";
b.title = "Chronicles of Narnia";
b.price = 9.99;
c.author = "Darren Shan";
c.title = "Procession of the Dead";
c.price = 14.99;
d.author = "Albert Einstein";
d.title = "Theory of Relativity";
d.price = 4.99;
shelf.add(a);
shelf.add(b);
shelf.add(c);
shelf.add(d);
cin.get();
return 0;
}
sortedList :: sortedList ()
{
head = NULL;
}
void sortedList :: add (itemType x)
{
node *prev = NULL;
node *ptr = NULL;
node *temp = NULL;
prev = NULL;
ptr = head;
while (ptr != NULL && compare(x, (*ptr).data == GREATER))
{
prev = ptr;
ptr = (*ptr).next;
}
temp = new node;
(*temp).data = x;
if (prev == NULL)
{
(*temp).next = head;
head = temp;
}
else
{
(*temp).next = ptr;
(*prev).next = temp;
}
}
compType compare (itemType x, itemType y)
{
if ( x.price > y.price)
{
return GREATER;
}
else if (x.price < y.price)
{
return LESSER;
}
else
{
return EQUAL;
}
}

