Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. struct node
  5. {
  6. int data;
  7. node* next;
  8. };
  9.  
  10. node* Head=NULL;
  11.  
  12. void print()
  13. {
  14. cout<<"Current Linked List : ";
  15.  
  16. node* curr=Head;
  17. while(curr!=NULL)
  18. {
  19. cout<<curr->data<<" ->";
  20. curr=curr->next;
  21. }
  22. cout<<endl;
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28. node* curr; //sudhu nia rakhla kisu assign korla na
  29.  
  30. int value,n;
  31.  
  32. cin>>n;
  33. cout<<endl;
  34.  
  35. for(int i=0;i<n;i++)
  36. {
  37.  
  38. cin>>value;
  39.  
  40. node* nptr= new node;
  41. nptr->data=value;
  42. nptr->next=NULL;
  43.  
  44. if(Head==NULL)
  45. {
  46. Head = nptr;
  47. curr = nptr;
  48. }
  49. else
  50. {
  51. curr->next=nptr;
  52. curr=nptr;
  53. }
  54.  
  55. }
  56.  
  57. print();
  58.  
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement