Blame view

SearchingSortingandBasicDataStructures/Queue/GeeksforGeeks.cpp 809 Bytes
eb0b70f67   Ronaldo   Updating the dire...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  //
  // Created by ronal on 2/11/2023.
  // Problem Description Link.
  // https://practice.geeksforgeeks.org/problems/geeksforgeeks/0
  
  #include <bits/stdc++.h>
  using namespace std;
  
  int GeeksForGeeks(queue<int> &q){
      int aux;
  
      if(q.size() == 1){
          return q.front();
  
      }else{
          while(!q.empty()){
              aux = q.front();
              q.pop();
              q.push(aux);
              q.pop();
  
              if(q.size() == 1){
                  break;
              }
          }
      }
      return q.front();
  }
  
  int main() {
      queue<int> q;
      int tests;
      int size;
  
      cin >> tests;
      for(int i = 0; i < tests; i++){
          cin >> size;
          for(int j = 1; j <= size; j++){
              q.push(j);
          }
          cout << GeeksForGeeks(q) << "
  ";
          q.pop();
      }
      return 0;
  }