Hello all, I have a linked list that inserts and removes left which of course means the data I am reading in from a file prints backwards. I have tried everything I can think of inorder to have it print in order. The closest I have come so far is printing out the first item, but then it ends. Any help would be greatly appreciated.
Node *head=NULL, tail=NULL, *p, *t;
void Insert_Left(Node * &head, Node * &tail, Node *p)
{
if (!head)
{
head = tail = p;// assign both when 1st Node created.
}
else
{
p->next = head;
//cout << p->info << ' ';
head = p;
}
}
void Insert_Right(Node * &head, Node * &tail, Node *p)
{
if (!head)
{
head = tail = p;// assign both when 1st Node created.
}
else
{
tail->next = p;
//cout << p->info << ' ';
tail = p;
}
}
This tail Node* won't allow you to Remove_Right though (trying to anticipate your next question). You would have to iterate through the list each time to do that.