Advertisement
Guest User

IntQueue - list

a guest
Nov 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct IntQueueNode {
  6. int value;
  7. IntQueueNode* next;
  8. };
  9.  
  10. class IntQueue {
  11. IntQueueNode* front;
  12. IntQueueNode* back;
  13. public:
  14. void add(int value) {
  15. IntQueueNode* node = new IntQueueNode;
  16. node->value = value;
  17. node->next = 0;
  18. if (!isntEmpty()) front = back = node;
  19. else {
  20. back->next = node;
  21. back = node;
  22. }
  23.  
  24. }
  25. int remove() {
  26. int val = front->value;
  27. IntQueueNode* f = front;
  28. front = front->next;
  29. delete f;
  30. return val;
  31.  
  32. }
  33. bool isntEmpty() {
  34. return (bool)front;
  35. }
  36. IntQueue(): front(0), back(0) {}
  37. ~IntQueue() {
  38. while (isntEmpty()) remove();
  39. }
  40. };
  41. int main() {
  42. IntQueue q, t;
  43. int n; cin >> n;
  44. fori (n) {
  45. int v; cin >> v;
  46. q.add(v);
  47. }
  48. int max = -1000;
  49. int val = 0;
  50. while (q.isntEmpty()) {
  51. t.add(val = q.remove());
  52. if (val > max) max = val;
  53. }
  54. while (t.isntEmpty()) {
  55. val = t.remove();
  56. if (val != max) q.add(val);
  57. }
  58. cout << "max: " << max << endl;
  59. while (q.isntEmpty()) cout << q.remove() << ' ';
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement