TAHMID37

link_list_traversal

Aug 24th, 2020 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. /*  TAHMID RAHMAN
  2.     DAMIAN FOREVER
  3.      MATH LOVER
  4.     NEVER GIVE UP
  5. */
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. #define pi acos(-1.0)
  9. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  10. #define ll long long
  11. #define pb push_back
  12. #define fi first
  13. #define se second
  14. #define in insert
  15. #define mp make_pair
  16. #define GCD(a,b) __gcd(a,b);
  17. #define endl "\n"
  18. #define FRU freopen("out.txt","w",stdout)
  19. #define FRO freopen("in.txt","r",stdin)
  20. #define INFLL 9223372036854775807
  21. #define debug 0
  22. #define MAXN   100001
  23. #define ar array
  24. const int mxN=2e5;
  25. const int MOD=1e9+7;
  26. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
  27. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  28.  
  29. struct node{
  30.   int data;
  31.   struct node*next;
  32. };
  33.  
  34. struct node* head=NULL;
  35. void in(int data)
  36. {
  37.     struct node*temp=(struct node*)malloc(sizeof(struct node));
  38.     temp->data=data;
  39.     temp->next=NULL;
  40.     if(head==NULL)
  41.     {
  42.         head=temp;
  43.     }
  44.     else
  45.     {
  46.         struct node* p=head;
  47.         while(p->next!=NULL)
  48.         {
  49.             p=p->next;
  50.         }
  51.         p->next=temp;
  52.     }
  53. }
  54. struct node* cur=NULL;
  55. void print()
  56. {
  57.     struct node* ptr=head;
  58.     while(ptr!=NULL)
  59.     {
  60.         printf("%d ",ptr->data);
  61.         ptr=ptr->next;
  62.     }
  63. }
  64.  
  65. bool isempty()
  66. {
  67.     return (head==NULL);
  68. }
  69.  
  70. int main()
  71. {
  72.    int t;
  73.    cin>>t;
  74.    while(t--)
  75.    {
  76.        string s,t;
  77.        int n;
  78.        t="P";
  79.        cin>>s;
  80.        if(s==t)
  81.        {
  82.            if(isempty()==1)
  83.             cout<<"The linked list is empty."<<endl;
  84.            else
  85.               print();
  86.               cout<<endl;
  87.  
  88.        }
  89.        else
  90.        {
  91.            cin>>n;
  92.            in(n);
  93.        }
  94.    }
  95.  
  96.  
  97. }
  98.  
  99.  
  100.  
Add Comment
Please, Sign In to add comment