fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11.  
  12. struct Node{
  13. Node* next;
  14. int data;
  15. };
  16.  
  17. Node* head= NULL;
  18. Node* previous=NULL;
  19.  
  20. void push(int data)
  21. {
  22. Node* current=new Node() ; //new
  23. current->data=data; //new with data
  24.  
  25. if(head==NULL){
  26. previous=current;
  27. head=current;
  28. return;
  29. }
  30.  
  31. previous->next=current;
  32. previous=current;
  33.  
  34. }
  35.  
  36. int main()
  37. {
  38. int arr[]={1,2,5,9,4};
  39. int n=sizeof(arr)/sizeof(arr[0]);
  40. int i;
  41. for(i=0;i<5;i++)
  42. {
  43.  
  44. push(arr[i]);
  45. }
  46.  
  47. Node* current=head;
  48.  
  49. while(current!=NULL)
  50. {
  51.  
  52. cout<<current->data<<endl;
  53. current=current->next;
  54.  
  55. }
  56.  
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
1
2
5
9
4