1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include<iostream> using namespace std; struct Node{ int data; struct Node*next; }; struct Node*head; void Insert(int x){ struct Node*temp=new Node(); temp->data=x; temp->next=NULL; if(head!=NULL) temp->next=head; head=temp; } void Print(){ struct Node*temp=head; cout<<"List is "; while(temp!=NULL){ cout<<temp->data; temp=temp->next; } cout<<endl; } int main(){ head=NULL; cout<<"How many numbers"<<endl; int n,i,x; cin>>n; for(i=0;i<n;i++){ cout<<"Enter the number"<<endl; cin>>x; Insert(x); Print(); } return 0; }
|