i m trying to do this program to get digits from a number using linked lists..but don't know something is wrong.a logical error:-/
at the place of actual output it shows nothing clear blank ecept the message.so here's the code:
//DigitNode.cpp
# define NULL 0
class DigiNode
{
private:
DigiNode* Front;
int digit;
public:
DigiNode()
{
digit=NULL;
Front=NULL;
}
DigiNode(int digit)
{
this->digit=digit;
Front=NULL;
}
void SetFront(DigiNode* Front)
{
this->Front=Front;
}
DigiNode* GetFront()
{
return Front;
}
void SetDigit(int digit)
{
this->digit=digit;
}
int GetDigit()
{
return digit;
}
};
DigitLink.cpp
# include "DigitNode.cpp"
# define NULL 0
# include <cmath>
class DigiLink
{
private:
DigiNode *Head, *CurNode;
public:
DigiLink()
{
Head=CurNode=NULL;
}
bool Empty()
{
if(Head->GetFront()==NULL)
return true;
else
return false;
}
void DigiNum(int x)
{
int r, q;
q=x;
while(q>0)
{
r=q%10;
q/=10;
CurNode=new DigiNode();
CurNode->SetDigit(r);
if(Head==NULL)
{
Head=CurNode;
return;
}
else
{
Head->SetFront(CurNode);
Head=CurNode;
}
}
}
int ShowDigit()
{
if(Empty())
throw "END";
else
{
CurNode=Head;
Head=Head->GetFront();
int i=CurNode->GetDigit();
delete CurNode;
return i;
}
}
};
now the main:
# include <iostream>
# include "DiGiTLinK.cpp"
using namespace std;
void main()
{
DigiLink D;
int x;
cout<<"\nInput The Number:";
cin>>x;
D.DigiNum(x);
cout<<"\nFollowing Are Your Input Elements In A Stack:\n";
while(true)
{
try
{
cout<<D.ShowDigit()<<", ";
}
catch (char *msg)
{
cout<<msg<<'\n';
break;
}
}
}