struct NODE{
int data;
NODE *next;
};
int main()
{
NODE * n;
NODE * pHead =NULL;
NODE * pTail =NULL;
cout<<"Enter Data: [Y]|[N] ";
cin>>option;
while(option!='n')
{
n = new NODE; //creating a new node
cout<<"\nEnter Some Data: "; //asking for users to enter data
cin>>data;
n->data = data; //storing data
if (pHead ==NULL) //checking if head is -1 / NULL
{
pHead = n; //set head to the first node created
}else{
pTail->next = n;
}
pTail = n;
n->next = NULL; //set next to -1 / NULL
cout<<"\nEnter More Data: [Y]|[N] "; //ask if the user wants to continue or no
cin>>option;
}
//Front Order using For Loop
cout<<"\nFront Order Using For Loop: ";
for (n=pHead; n!=NULL; n=n->next)
{
cout<<n->data<<" "; //Print Data
}
return 0 ;
}
input 1 2 3 4
output Front Order Using For Loop: 1 2 3
my question is how can i use the for loop to print the reverse order i am able to do the recursive one but unable to use a for loop to print the reverse order