Hey, so as you can tell, this is my first attempt at writing a class. I put in a mock int main() in order to follow what exactly is going wrong. As far as I can tell, every time the struct in push is used, it always has the same address. The idea is 'first' is the first struct that's pushed onto the queue (using setValues) and 'last' is the most current value pushed onto the queue. I haven't really gotten to working with pop, but I don't need it to return a value, in case you're wondering. Really appreciate any and all help...
And sorry if my code offends ;)
//Postfix with Objects
#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <stack>
using namespace std;
struct entry{
bool operation;
char op;
int num;
entry * next;
};
class Queue{
public:
entry first;
entry * last;
void setValues(entry);
void pop();
void push(entry);
entry front();
bool empty();
};
void Queue::setValues(struct entry first1){
first=first1;
last=&first;
}
void Queue::pop(){
entry * temp1=new entry;
temp1=last;
int i=0;
if (last==0){
cout<<"QUEUE EMPTY"<<endl;
return;
}
if(last->next==0){
last=0;
return;
}
cout<<first.num<<" " <<first.next<<endl;
entry returner;
while (temp1->next!=0){
temp1=temp1->next;
i++;
}
i--;
temp1=last;
while (i!=0){
temp1=temp1->next;
i--;
}
returner.num=(temp1->num);
returner.operation=(temp1->operation);
returner.op=(temp1->op);
returner.next=0;
first=returner;
}
void Queue::push(struct entry x){
x.next=last;
last=&x;
}
entry Queue::front(){
return first;
}
bool Queue::empty(){
if(last==0)
return true;
else
return false;
}
int main() {
entry a = {false, 'a', 1, NULL};
entry b = {true, 'b', 2, NULL};
entry c = {false, 'c', 3, NULL};
Queue myQueue;
myQueue.setValues(a);
myQueue.push(b);
myQueue.push(c);
cout << myQueue.last->op << endl <<
myQueue.last->next->op << endl <<
myQueue.last->next->next->op << endl;
return 0;
}