Hi,,, i'm new here and i have a homework and really don't know how to solve it... i'm trying my best but there no luck
Please I need your help with node and singly linked list in C++...
it is a homework:
modify the list class by adding a member function for reversing the list:
i need a reverse function
void reverse ()
and also add a new item at a special position:
i need the function insert
void insert (double x, int pos)
pls help me
Code:
class Node{
private:
Node *head;
Node *tail;
Node *next;
int info;
public:
bool IsEmpty ()
{
if (head==0)
return true;
else
return false;
}
Node (int data, Node *ptr=0)
{
info=data;
next=ptr;
}
void AddToHead (int data)
{
if (!IsEmpty ())
{
head= new Node (data);
if (tail !=0)
{
tail->next= new Node (data);
tail= tail->next;
}
else
head= tail= new Node(data);
}
}
void PrintAll(int data)
{
for (Node *temp=head; temp !=0; temp= temp->next)
cout<< temp->info<<" ";
cout<<endl;
}
/* void Reverse ()
{
Node *p=head, *rev=0;
while (!IsEmpty())
{
p= p->next;
p->next = rev;
rev = p;
cout<< "The List as reversed: "<< p;
}
cout<< endl;
}*/