Hi I have a piece of code. It's print for me the numbers I enterd but in reverse order that I would like to. How may I change that?
thx
#include<iostream>
#include<conio.h>
using namespace std;
struct Node
{
int data;
Node* link;
};
class Q
{
public:
Q();
void get_input(int);
void display_input();
private:
void display(Node* node);
Node* head;
};
int main()
{
Q q1;
int number;
cout<<"How many numbers : ";
cin>>number;
for (int i=0;i<number;i++)
{
q1.get_input(number);
}
q1.display_input();
getch();
return 0;
}
Q::Q()
{
head=NULL;
}
void Q::get_input(int number)
{
cout<<"Enter a number: ";
Node* temp;
temp=new Node;
cin>>temp->data;
temp->link=head;
head=temp;
}
void Q::display_input()
{
cout<<"The output is equall to: ";
display(head);
}
void Q::display(Node* head)
{
if(head==NULL)
return;
cout<<head->data;
cout<<" ";
display(head->link);
}