I am new to C++ and I'm making a linked list. I keep running into issues when trying to display the contents of my linked list. It either shows random numbers, deletes items from it, or crashes completely. I'm not sure how to fix it or if the issue is coming from elsewhere in the program, but I'm not sure from where since the rest of the program runs fine.
class CarNode {
public:
CarNode() : m_pNext(0), m_ticketNum(0) { }
~CarNode();
CarNode(CarNode &): m_pNext(0), m_ticketNum(0) { }
void SetNext(CarNode* p){m_pNext=p;}
void SetTicketNum(int tN){m_ticketNum=tN;}
CarNode *GetNext(void){return(m_pNext);}
int GetTicketNum(void){return(m_ticketNum);}
private:
int m_ticketNum;
CarNode *m_pNext;
};
class CAlley {
public:
CAlley () : m_pTop(0), mSize(0), mMaxSize(MAXSIZE) { }
~CAlley () {}
CAlley (CAlley &):m_pTop(0), mSize(0), mMaxSize(MAXSIZE) { }
int Park(int);
void Retrieve(int,CAlley *);
void Terminate();
void Display();
private:
void SetTop(CarNode *p){m_pTop=p;}
bool Empty(){return ((mSize==0) ? true : false);}
bool Full() {return ((mSize==MAXSIZE) ? true : false);}
int Push(CarNode *);
CarNode * Pop();
CarNode *m_pTop;
int mSize;
int mMaxSize;
};
void CAlley::Display()
{
cout << "Alley A:\t";
CarNode * pCurr = m_pTop;
while (pCurr != NULL)
{
cout << pCurr->GetTicketNum();
if(pCurr->GetNext()!=NULL)
cout<< '\t';
pCurr=pCurr->GetNext();
}
cout << '\n';
}
Aucun commentaire:
Enregistrer un commentaire