Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct queue
- {
- int value;
- struct queue *next;
- };
- void push(queue* &NEXT, const int VALUE)
- {
- queue *MyQueue = NEXT;
- while (MyQueue->next) {
- MyQueue = MyQueue->next;
- }
- queue *newEl = new queue;
- newEl->value = VALUE;
- MyQueue->next = newEl;
- }
- int pop(queue* &NEXT)
- {
- int temp = NEXT->value;
- queue *MyQueue = NEXT;
- NEXT = NEXT->next;
- delete MyQueue;
- return temp;
- }
- void main() {
- setlocale(LC_ALL, "Russian");
- queue *p;
- queue *odd;
- queue *even;
- int n;
- cin >> n;
- for (int i = 0; i < n; i++) {
- int q;
- cin >> q;
- push(p, q);
- }
- int oddCnt = 0, evenCnt = 0;
- for (int i = 0; i < n; i++) {
- int q = pop(p);
- if (q % 2 == 0) {
- push(even, q);
- evenCnt++;
- } else {
- push(odd, q);
- oddCnt++;
- }
- }
- for (int i = 0; i < evenCnt; i++) {
- cout << pop(even) << " ";
- }
- for (int i = 0; i < oddCnt; i++) {
- cout << pop(odd) << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement