this is my program for list implementation in C++. And I want to print the first element in it. I write element until I reach 0
Can You show me the way to do it. Thanks
#include "stdafx.h"
#include "iostream"
using namespace std;
struct Node {
int data;
Node *next;
};
int main()
{
Node *first = 0;
Node *p;
cout << "Enter a list" << endl;
int i;
while (true) {
cin >> i;
if (i == 0) break;
p = new Node;
p -> data = i;
p -> next = first ;
first = p;
}
cout << "List: ";
p = first;
while (p) {
cout << p -> data;
p = p -> next;
}
cout << endl;
return 0;
}