#include <iostream>
using namespace std;
typedef struct List {
int data;
List*link;
List(){
data=0;
link=NULL;}
}SList;
SList*L,*P,*temp;
int x;
SList*createnew(int x){
temp=new List;
temp->data = x;
temp->link = NULL;
return (temp);
}
SList*findLast(SList*L){
temp=L;
while(temp->link != NULL)
temp=temp->link;
return (temp);
}
void printList(SList*L){
temp=L;
while(temp!= NULL){
cout<<temp->data<<endl;
temp=temp->link;
}
}
int count(SList*L){
temp=L;
int i=0;
while (temp != NULL){
i++;
temp=temp->link;
}
return (i);
}
void addend (){
L=NULL;
cout<<"Please enter a number "; cin>>x;
do{
if(cin.eof())
break;
P=createnew(x);
if(L!=NULL){
temp=findLast(L);
temp->link=P;}
else
L=P;
cout<<"Please enter a number ";
}while ( cin>>x);
}
int main(){
addend();
printList(L);
return 0;
}
Why i must enter ctrl+z 2 times to out from the loop..?