Tuesday of this past week I decided I would give myself a long over due refresher course in C++. So I started with the tutorials and when I got to Linked Lists I got stuck and a practice program I was writing.
Code:
#include <iostream>
using namespace std;
struct node
{
char *Inv;
node *pNext;
node *pPrev;
};
node *pHead;
node *pTail;
void AddNode( node *pNode);
int main()
{
char *temp;
node *list;
while (temp != "done")
{
cout<<"Enter inventory item: ";
cin>>temp;
cin.ignore();
list = new node;
list->Inv=temp;
AddNode(list);
}
cout<<"\n\n\n...Ready to print inventory\n\n";
for (list = pHead;list != NULL;list = list->pNext)
{
cout<<list->Inv;
}
}
void AddNode( node *pNode)
{
if ( pHead == NULL )
{
pHead = pNode;
pNode->pPrev = NULL;
}
else
{
pTail->pNext = pNode;
pNode->pPrev = pTail;
}
pTail = pNode;
pNode->pNext = NULL;
}
The program compiles and runs, but when I type the word done in it doesn't continue on to printing out the list it asks for another inventory item.
Any ideas?