Advertisement
J00ker

Untitled

Apr 1st, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #define Nmax 10001
  3.  
  4. using namespace std;
  5.  
  6. struct Coada
  7. {
  8. int q[Nmax];
  9. int pr, ul;
  10.  
  11. void Init()
  12. {
  13. pr = 0;
  14. ul = - 1;
  15. }
  16.  
  17. int Empty()
  18. {
  19. if(pr <= ul) return 0;
  20. return 1;
  21. }
  22.  
  23. void Push(int x)
  24. {
  25. ul++;
  26. q[ul] = x;
  27. }
  28.  
  29. void Pop()
  30. {
  31. if(!Empty()) pr++;
  32. }
  33.  
  34. int Front()
  35. {
  36. return q[pr];
  37. }
  38.  
  39. int Size()
  40. {
  41. return ul - pr + 1;
  42. }
  43. };
  44.  
  45. int main()
  46. {
  47. ///--Initializari si alte chestii--
  48. int i;
  49. int a2[] = {5, 3, 9, 1, 4, 7, 1}, n = 7;
  50. int b2[] = {9, 1, 4, 2, 4, 10, 0, 6, 3, 7}, m = 10;
  51. Coada a, b;
  52. a.Init(); b.Init();
  53. for(i = 0; i < n; i++)
  54. a.Push(a2[i]);
  55. for(i = 0; i < m; i++)
  56. b.Push(b2[i]);
  57.  
  58. ///--Programu--
  59. for(i = 0; i < n; i++) /// while(!a.Empty())
  60. {
  61. b.Push(a.Front());
  62. a.Pop();
  63. }
  64. for(i = 0; i < m; i++)
  65. {
  66. a.Push(b.Front());
  67. b.Pop();
  68. }
  69.  
  70. ///--Afisari--
  71. cout << "a: ";
  72. while(!a.Empty())
  73. {
  74. cout << a.Front() << " "; a.Pop();
  75. }
  76. cout << "\nb: ";
  77. while(!b.Empty())
  78. {
  79. cout << b.Front() << " "; b.Pop();
  80. }
  81. cout << "\n";
  82.  
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement