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