Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<iostream>
- using namespace std;
- struct Node
- {
- int data;
- Node* next;
- };
- Node* head;
- void insert(int x)
- {
- Node* newnode;
- newnode = (Node*)malloc(sizeof(Node));
- newnode->data=x;
- newnode->next=head;
- head=newnode;
- }
- void print()
- {
- Node* newnode;
- cout<<"List is : ";
- while(newnode!=NULL)
- {
- cout<<newnode->data<<" ";
- newnode=newnode->next;
- }
- cout<<"\n";
- }
- int main()
- {
- head=NULL;
- int i, n, x;
- cout<<"How many nodes?\n";
- cin>>n;
- for(i=0;i<n;i++)
- {
- cout<<"Enter the number: \n";
- cin>>x;
- insert(x);
- print();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement