int arrayQueue::takeAway()
{
char letter;
if (empty())
return -1;
else {
Data *p, info;
if (top == NULL)
{
cout << "Error stack empty\n";
} else {
p = top; //top is another Data struct instance
info.value = p->value;
top = p->next;
delete p;
return info.value;
}
}
}
For my data structures course we are creating a queue using pointers and linked lists, however I cannot figure out how to point to the FIRST value. As the code is now, it points to the LAST value entered, which isn't useful in a queue setting. I searched for other examples, but I can only find examples that use more than one linked list. If anyone has any ideas it would be much appreciated!
edit: Here's how I am adding things to the queue
void arrayQueue::addToQueue(char x)
{
if (full())
cout << "Error, queue full \n";
else {
Data *p;
p = new Data;
p->value = x;
p->next = top;
top = p;
}
}
and this is my struct
struct Data
{
char value;
Data *next;
};