Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct IntQueueNode {
- int value;
- IntQueueNode* next;
- };
- class IntQueue {
- IntQueueNode* front;
- IntQueueNode* back;
- public:
- void add(int value) {
- IntQueueNode* node = new IntQueueNode;
- node->value = value;
- node->next = 0;
- if (!isntEmpty()) front = back = node;
- else {
- back->next = node;
- back = node;
- }
- }
- int remove() {
- int val = front->value;
- IntQueueNode* f = front;
- front = front->next;
- delete f;
- return val;
- }
- bool isntEmpty() {
- return (bool)front;
- }
- IntQueue(): front(0), back(0) {}
- ~IntQueue() {
- while (isntEmpty()) remove();
- }
- };
- int main() {
- IntQueue q, t;
- int n; cin >> n;
- fori (n) {
- int v; cin >> v;
- q.add(v);
- }
- int max = -1000;
- int val = 0;
- while (q.isntEmpty()) {
- t.add(val = q.remove());
- if (val > max) max = val;
- }
- while (t.isntEmpty()) {
- val = t.remove();
- if (val != max) q.add(val);
- }
- cout << "max: " << max << endl;
- while (q.isntEmpty()) cout << q.remove() << ' ';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement