Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <ctime>
  5. using namespace std;
  6. struct stiva{
  7. int info,cul;
  8. stiva *urm;
  9. }*vf;
  10. struct tija{
  11. int info;
  12. tija *urm;
  13. }*t[101],*q;
  14. void push(stiva *&vf,int x,int y)
  15. {
  16. stiva *q;
  17. if(vf==0)
  18. {
  19. vf=new stiva;
  20. vf->info=x;
  21. vf->cul=y;
  22. vf->urm=0;
  23. }
  24. else
  25. {
  26. q=new stiva;
  27. q->info=x;
  28. q->cul=y;
  29. q->urm=vf;
  30. vf=q;
  31. }
  32. }
  33. void adaug(tija *&vf, int x)
  34. {
  35. tija *q;
  36. if(vf==0)
  37. {
  38. vf=new tija;
  39. vf->info=x;
  40. vf->urm=0;
  41. }
  42. else
  43. {
  44. q=new tija;
  45. q->info=x;
  46. q->urm=vf;
  47. vf=q;
  48. }
  49. }
  50. void sim(stiva *s)
  51. {
  52. stiva *q;
  53. for(q=s;q;q=q->urm)
  54. adaug(t[q->cul],q->info);
  55. }
  56. int main()
  57. {
  58. int ma,n,x,i;
  59. vf=0;ma=0;
  60. cin>>n;
  61. srand(time(NULL));
  62. for(int i=1;i<=n;++i)
  63. {
  64. x=rand()%5;
  65. if(x>ma)
  66. ma=x;
  67. cout<<x<<" ";
  68. push(vf,i,x);
  69. }
  70. cout<<'\n';
  71. sim(vf);
  72. for(i=1;i<=ma;++i)
  73. {
  74. for(q=t[i];q;q=q->urm)
  75. cout<<q->info<<' ';
  76. cout<<'\n';
  77. }
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement