Advertisement
TAHMID37

Link_list_revisited_TAHMID_

Jul 15th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.62 KB | None | 0 0
  1. //Task___1
  2. /*  TAHMID RAHMAN
  3.     DAMIAN FOREVER
  4.      MATH LOVER
  5.     NEVER GIVE UP
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. #define pi acos(-1.0)
  10. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  11. #define ll long long
  12. #define pb push_back
  13. #define fi first
  14. #define se second
  15. #define in insert
  16. #define mp make_pair
  17. #define GCD(a,b) __gcd(a,b);
  18. #define endl "\n"
  19. #define FRU freopen("out.txt","w",stdout)
  20. #define FRO freopen("in.txt","r",stdin)
  21. #define INFLL 9223372036854775807
  22. #define debug 0
  23. #define MAXN   100001
  24. #define ar array
  25. const int mxN=2e5;
  26. const int MOD=1e9+7;
  27. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
  28. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  29.  
  30.  
  31. struct player{
  32.  
  33.   string player_name;
  34.    int age;
  35.    int rating;
  36.    double salary;
  37.    string pos;
  38.    struct player* next;
  39. };
  40.  
  41.  
  42. struct club{
  43.    string club_name;
  44.    int year;
  45.    double revenue;
  46.    player players;
  47.   struct club* next;
  48.  
  49. };
  50.  club *head=NULL;
  51.  club *root=NULL;
  52. int main()
  53. {
  54.    return 0;
  55.  
  56. }
  57.  
  58. //Task__2
  59. /*  TAHMID RAHMAN
  60.     DAMIAN FOREVER
  61.      MATH LOVER
  62.     NEVER GIVE UP
  63. */
  64. #include<bits/stdc++.h>
  65. using namespace std;
  66. #define pi acos(-1.0)
  67. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  68. #define ll long long
  69. #define pb push_back
  70. #define fi first
  71. #define se second
  72. #define in insert
  73. #define mp make_pair
  74. #define GCD(a,b) __gcd(a,b);
  75. #define endl "\n"
  76. #define FRU freopen("out.txt","w",stdout)
  77. #define FRO freopen("in.txt","r",stdin)
  78. #define INFLL 9223372036854775807
  79. #define debug 0
  80. #define MAXN   100001
  81. #define ar array
  82. const int mxN=2e5;
  83. const int MOD=1e9+7;
  84. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
  85. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  86. struct player{
  87.  
  88.   string player_name;
  89.    int age;
  90.    int rating;
  91.    double salary;
  92.    string pos;
  93.    struct player* next;
  94. };
  95.  
  96. struct club{
  97.    string club_name;
  98.    int year;
  99.    float revenue;
  100.    player players;
  101.   struct club* next;
  102.  
  103. };
  104.  club *head=NULL;
  105.  club *root = NULL;
  106.  
  107. int len()
  108. {
  109.     ll lens=0;
  110.     struct club *p=head;
  111.     while(p!=NULL)
  112.         {
  113.             lens++;
  114.             p=p->next;
  115.         }
  116.     return lens;
  117. }
  118.  
  119. void in_ser()
  120. {
  121.   int n,y;
  122.   string nam;
  123.   float d;
  124.   struct club*temp=(struct club*)malloc(sizeof(struct club));
  125.   cout<<"Enter name:";
  126.   cin>>nam;
  127.   temp->club_name=nam;
  128.   cout<<"Enter year of formation:";
  129.   cin>>y;
  130.   temp->year=y;
  131.   cout<<"Enter yearly revenue:";
  132.   cin>>d;
  133.   temp->revenue=d;
  134.   cout<<"Enter position in list:";
  135.   temp->next=NULL;
  136.   cin>>n;
  137.   int siz=len();
  138.    if(n==1)
  139.    {
  140.        temp->next=head;
  141.        head=temp;
  142.        return;
  143.    }
  144.    else if(siz+1<n)
  145.    {
  146.        cout<<"Invalid Position"<<endl;
  147.        return;
  148.    }
  149.  
  150.    struct club* temp1=head;
  151.    for(int i=0;i<n-2;i++)
  152.    {
  153.        temp1=temp1->next;
  154.    }
  155.    temp->next=temp1->next;
  156.    temp1->next=temp;
  157.  
  158. }
  159. void del()
  160. {
  161.  
  162.     struct club *cur=head;
  163.     struct club *prev=NULL;
  164.     cout<<"Enter the club you want to delete:"<<endl;
  165.     string s;
  166.     cin>>s;
  167.     if(head==NULL)
  168.     {
  169.         cout<<"Invalid no Clubs found"<<endl;
  170.     }
  171.     else
  172.     {
  173.         while(cur->club_name!=s)
  174.         {
  175.             if(cur->next==NULL)
  176.             {
  177.                 cout<<"NO Club found"<<endl;
  178.             }
  179.             else
  180.             {
  181.                 prev=cur;
  182.                 cur=cur->next;
  183.             }
  184.  
  185.         }
  186.         if(cur==head)
  187.         {
  188.             head=head->next;
  189.         }
  190.         else
  191.         {
  192.             prev->next=cur->next;
  193.         }
  194.  
  195.     }
  196.  
  197.  
  198.  
  199.  
  200. }
  201.  
  202. void print()
  203. {
  204.  
  205.  struct club *ptr=head;
  206.  while(ptr!=NULL)
  207.  {
  208.     cout<<ptr->club_name<<endl;
  209.     cout<<ptr->year<<endl;
  210.     cout<<ptr->revenue<<endl;
  211.     ptr=ptr->next;
  212.  }
  213.  
  214. }
  215. void print_opt()
  216. {
  217.     cout<<"What to you want to do?"<<endl;
  218.     cout<<"1.  Create Club"<<endl;
  219.     cout<<"2.  Delete Club"<<endl;
  220.     cout<<"3.  View Club info"<<endl;
  221. }
  222. int main()
  223. {
  224.    cout<<"La Liga Database Intializing..."<<endl;
  225.    int choice;
  226.    bool f=true;
  227.    while(f)
  228.    {
  229.        print_opt();
  230.        cout<<"Choice:";
  231.        cin>>choice;
  232.        if(choice==1)
  233.        {
  234.  
  235.            in_ser();
  236.            cout<<"............."<<endl;
  237.        }
  238.        else if(choice==2)
  239.        {
  240.            del();
  241.            cout<<"............."<<endl;
  242.        }
  243.        else if(choice==3)
  244.        {
  245.            int z=len();
  246.            if(z==0)
  247.             cout<<"No club to show"<<endl;
  248.            else
  249.            {
  250.            cout<<"Showing Club list:"<<endl;
  251.            print();
  252.            }
  253.            cout<<"............."<<endl;
  254.        }
  255.        else
  256.        {
  257.            cout<<"La liga database Terminating......"<<endl;
  258.            f=false;
  259.        }
  260.  
  261.    }
  262. }
  263.  
  264. //Task__3
  265. /*  TAHMID RAHMAN
  266.     DAMIAN FOREVER
  267.      MATH LOVER
  268.     NEVER GIVE UP
  269. */
  270. #include<bits/stdc++.h>
  271. using namespace std;
  272. #define pi acos(-1.0)
  273. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  274. #define ll long long
  275. #define pb push_back
  276. #define fi first
  277. #define se second
  278. #define in insert
  279. #define mp make_pair
  280. #define GCD(a,b) __gcd(a,b);
  281. #define endl "\n"
  282. #define FRU freopen("out.txt","w",stdout)
  283. #define FRO freopen("in.txt","r",stdin)
  284. #define INFLL 9223372036854775807
  285. #define debug 0
  286. #define MAXN   100001
  287. #define ar array
  288. const int mxN=2e5;
  289. const int MOD=1e9+7;
  290. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
  291. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  292. struct player{
  293.  
  294.   string player_name;
  295.    int age;
  296.    int rating;
  297.    double salary;
  298.    string pos;
  299.    struct player* next;
  300. };
  301.  
  302. struct club{
  303.    string club_name;
  304.    int year;
  305.    float revenue;
  306.    player players;
  307.   struct club* next;
  308.  
  309. };
  310.  club *head=NULL;
  311.  club *root = NULL;
  312.  
  313. int len()
  314. {
  315.     ll lens=0;
  316.     struct club *p=head;
  317.     while(p!=NULL)
  318.         {
  319.             lens++;
  320.             p=p->next;
  321.         }
  322.     return lens;
  323. }
  324.  
  325. void in_ser()
  326. {
  327.   int n,y;
  328.   string nam;
  329.   float d;
  330.   struct club*temp=(struct club*)malloc(sizeof(struct club));
  331.   cout<<"Enter name:";
  332.   cin>>nam;
  333.   temp->club_name=nam;
  334.   cout<<"Enter year of formation:";
  335.   cin>>y;
  336.   temp->year=y;
  337.   cout<<"Enter yearly revenue:";
  338.   cin>>d;
  339.   temp->revenue=d;
  340.   cout<<"Enter position in list:";
  341.   temp->next=NULL;
  342.   cin>>n;
  343.   int siz=len();
  344.    if(n==1)
  345.    {
  346.        temp->next=head;
  347.        head=temp;
  348.        return;
  349.    }
  350.    else if(siz+1<n)
  351.    {
  352.        cout<<"Invalid Position"<<endl;
  353.        return;
  354.    }
  355.  
  356.    struct club* temp1=head;
  357.    for(int i=0;i<n-2;i++)
  358.    {
  359.        temp1=temp1->next;
  360.    }
  361.    temp->next=temp1->next;
  362.    temp1->next=temp;
  363.  
  364. }
  365. void del()
  366. {
  367.  
  368.     struct club *cur=head;
  369.     struct club *prev=NULL;
  370.     cout<<"Enter the club you want to delete:"<<endl;
  371.     string s;
  372.     cin>>s;
  373.     if(head==NULL)
  374.     {
  375.         cout<<"Invalid no Clubs found"<<endl;
  376.     }
  377.     else
  378.     {
  379.         while(cur->club_name!=s)
  380.         {
  381.             if(cur->next==NULL)
  382.             {
  383.                 cout<<"NO Club found"<<endl;
  384.             }
  385.             else
  386.             {
  387.                 prev=cur;
  388.                 cur=cur->next;
  389.             }
  390.  
  391.         }
  392.         if(cur==head)
  393.         {
  394.             head=head->next;
  395.         }
  396.         else
  397.         {
  398.             prev->next=cur->next;
  399.         }
  400.  
  401.     }
  402.  
  403. }
  404.  
  405.  
  406. void print()
  407. {
  408.  
  409.  struct club *ptr=head;
  410.  while(ptr!=NULL)
  411.  {
  412.     cout<<ptr->club_name<<endl;
  413.     cout<<ptr->year<<endl;
  414.     cout<<ptr->revenue<<endl;
  415.     ptr=ptr->next;
  416.  }
  417.  
  418. }
  419.  
  420. void swaps()
  421. {
  422.     cout<<"Which to position you want to swap:"<<endl;
  423.     int x,y;
  424.     cin>>x>>y;
  425.  
  426.     struct club *prev_x=NULL, *current_x=head;
  427.     for(int i=1; i<=x-1 && current_x; i++)
  428.     {
  429.         prev_x=current_x;
  430.         current_x=current_x->next;
  431.     }
  432.     struct club *prev_y=NULL, *current_y=head;
  433.     for(int i=1; i<=y-1 && current_y; i++)
  434.     {
  435.         prev_y=current_y;
  436.         current_y=current_y->next;
  437.     }
  438.     if(prev_x!=NULL)
  439.     {
  440.         prev_x->next=current_y;
  441.     }
  442.     else
  443.     {
  444.         head=current_y;
  445.     }
  446.     if(prev_y!=NULL)
  447.     {
  448.         prev_y->next=current_x;
  449.     }
  450.     else
  451.     {
  452.         head=current_x;
  453.     }
  454.     struct club*temp;
  455.     temp=current_y->next;
  456.     current_y->next=current_x->next;
  457.     current_x->next=temp;
  458.  
  459. }
  460.  
  461. void print_opt()
  462. {
  463.     cout<<"What to you want to do?"<<endl;
  464.     cout<<"1.  Create Club"<<endl;
  465.     cout<<"2.  Delete Club"<<endl;
  466.     cout<<"3.  View Club info"<<endl;
  467.     cout<<"4.  Swap Clubs"<<endl;
  468. }
  469. int main()
  470. {
  471.    cout<<"La Liga Database Intializing..."<<endl;
  472.    int choice;
  473.    bool f=true;
  474.    while(f)
  475.    {
  476.        print_opt();
  477.        cout<<"Choice:";
  478.        cin>>choice;
  479.        if(choice==1)
  480.        {
  481.  
  482.            in_ser();
  483.            cout<<"............."<<endl;
  484.        }
  485.        else if(choice==2)
  486.        {
  487.            del();
  488.            cout<<"............."<<endl;
  489.        }
  490.        else if(choice==3)
  491.        {
  492.            int z=len();
  493.            if(z==0)
  494.             cout<<"No club to show"<<endl;
  495.            else
  496.            {
  497.             cout<<"Show club list:"<<endl;
  498.             print();
  499.            }
  500.            cout<<"............."<<endl;
  501.        }
  502.        else if(choice==4)
  503.        {
  504.            swaps();
  505.            cout<<"............."<<endl;
  506.  
  507.        }
  508.        else
  509.        {
  510.            cout<<"La liga database Terminating......"<<endl;
  511.            f=false;
  512.        }
  513.  
  514.    }
  515. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement