Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct node
- {
- int data;
- node* next;
- };
- node* head;
- void insert(int x)
- {
- node* temp=new node();
- temp->data=x;
- temp->next=head;
- // if(head!=temp) temp->next=head
- head=temp;
- }
- void print()
- {
- node* temp=head;
- cout<<"list is ";
- while (temp!=NULL)
- {cout<<temp->data;
- temp=temp->next;
- }
- }
- int main()
- {
- head=NULL;
- cout<<"how many numbers?";
- int n,x;
- cin>>n;
- cout<<"Enter the number";
- for (int i=0;i<n;i++)
- {
- cin>>x;
- insert(x);
- print();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment