Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. struct queue
  10. {
  11.     int value;
  12.     struct queue *next;
  13. };
  14.  
  15. void push(queue* &NEXT, const int VALUE)
  16. {
  17.     queue *MyQueue = NEXT;
  18.     while (MyQueue->next) {
  19.         MyQueue = MyQueue->next;
  20.     }
  21.    
  22.     queue *newEl = new queue;
  23.     newEl->value = VALUE;
  24.    
  25.     MyQueue->next = newEl;
  26. }
  27.  
  28. int pop(queue* &NEXT)
  29. {
  30.     int temp = NEXT->value;
  31.     queue *MyQueue = NEXT;
  32.     NEXT = NEXT->next;
  33.     delete MyQueue;
  34.     return temp;
  35. }
  36.  
  37. void main() {
  38.     setlocale(LC_ALL, "Russian");
  39.    
  40.     queue *p;
  41.     queue *odd;
  42.     queue *even;
  43.    
  44.     int n;
  45.     cin >> n;
  46.    
  47.     for (int i = 0; i < n; i++) {
  48.         int q;
  49.         cin >> q;
  50.         push(p, q);
  51.     }
  52.    
  53.     int oddCnt = 0, evenCnt = 0;
  54.     for (int i = 0; i < n; i++) {
  55.         int q = pop(p);
  56.         if (q % 2 == 0) {
  57.             push(even, q);
  58.             evenCnt++;
  59.         } else {
  60.             push(odd, q);
  61.             oddCnt++;
  62.         }
  63.     }
  64.    
  65.     for (int i = 0; i < evenCnt; i++) {
  66.         cout << pop(even) << " ";
  67.     }
  68.    
  69.     for (int i = 0; i < oddCnt; i++) {
  70.         cout << pop(odd) << " ";
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement