Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Node{
  6. int data;
  7. Node* next;
  8. };
  9.  
  10. Node* head;
  11.  
  12. void insert(int x);
  13. void print();
  14.  
  15. int main(){
  16. head = NULL;
  17. int n, x;
  18. cout<<"How many numbers?"<<endl;
  19. cin >> n;
  20.  
  21. for(int i =0;i<n;i++){
  22. cout<<"Enter number: "<<endl;
  23. cin >> x;
  24. insert(x);
  25. print();
  26. }
  27. return 0;
  28. }
  29.  
  30. void insert(int x){
  31.  
  32. Node* temp = new Node();
  33.  
  34. temp->data = x;
  35. temp->next = head;
  36. head = temp;
  37. }
  38.  
  39. void print(){
  40.  
  41. Node* temp;
  42. temp = head;
  43. cout << "List: "<<endl;
  44. while(temp!=NULL){
  45. cout << temp->data<<" ";
  46. temp = temp->next;
  47. }
  48. cout << endl;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement