My overloaded operator isn't initializing the value passed through it. Please help!!! and yes I am aware that my insert function isn't complete...
#include <iostream>
using namespace std;
struct Node{
int value;
Node * next;
};
class linkedList {
public:
linkedList () {first=0; length=0;}
bool operator > (int a) ;
void displayList ();
bool Insert (int i, int a);
private:
Node* first;
int length;
};
int main()
{
linkedList L;
L>6;
//L>9;
// L>3;
// L>9;
L.displayList();
return 0;
}
bool linkedList::operator > (int a)
{
if (length==0)
{
first->value=a;
first->next=0;
length++;
return true;
}
else
{
Node* newn;
Node* temp;
newn=new Node;
temp=new Node;
for (int i=0; i<=length; i++)
{
if (i=0)
temp=first->next;
if (i<length)
temp=temp->next;
if (i=length)
{
temp->next=newn;
newn->value=a;
newn->next=0;
length++;
}
}
delete temp;
return true;
}
return false;
}
void linkedList::displayList()
{
Node* temp;
temp = new Node;
cout << endl << "The elements of the linked list are: ";
for (int i=0; i<=length; i++)
{
if (i=0)
{
cout << first->value << " ";
temp=first->next;
}
else
{
cout << temp->value << " ";
temp=temp->next;
}
}
cout << endl;
}
bool linkedList::Insert(int i, int a)
{
return true;
}