看我是不是很爱学习 static int max = 1005; static class queue { int a[] = new int[max]; int first, ref, size; queue(int f, int r, int s) { first = f; ref = r; s = size; } int add(int x, int n) { if(size == n) { return x; }else { a[r
static int max = 1005;
static class queue {
int a[] = new int[max];
int first, ref, size;
queue(int f, int r, int s) {
first = f;
ref = r;
s = size;
}
int add(int x, int n) {
if(size == n) {
return x;
}else {
a[ref] = x;
ref = (++ref) % n;
size++;
return -1;
}
}
}
gistfile1.txt
static int max = 1005;
static class stack {
int num;
int top;
int a[] = new int[max];
stack(int top) {
this.top = top;
}
int add(int x, int n) {
if(top == n) {
return x;
}else {
a[top++] = x;
return -1;
}
}
}
The first line will be an integer T, which is the number of test cases. (1 <= T <= 10) For each test case, the first line will be an integer n (1 <= n <= 105) Then there will be n lines, each line will be one of the following cases: 1 1 x: push_first x
/*The first line will be an integer T, which is the number of test cases. (1 <= T <= 10)
For each test case, the first line will be an integer n (1 <= n <= 105)
Then there will be n lines, each line will be one of the following cases:
1 1 x: push_first x
1 2: pop_first
2 1 x: push_last x
2 2:pop_last
(0 <= x <= 103)
The input ensures that when you pop, there always are some elements in the queue.*/
import java.util.*;
import java.io.*;
public class Main {
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
InputReader in = new InputReader(System.in);
int T = in.nextInt();
while(T-->0) {
int array[] = new int[2000020];
int h = 100101;
int t = 100100;
int n = in.nextInt();
StringBuilder sb = new StringBuilder();
while(n-->0) {
int c = in.nextInt();
if(c == 2) {
int a = in.nextInt();
if(a == 1) {
int x = in.nextInt();
array[++t] = x;
}else {
t--;
}
}else {
int b = in.nextInt();
if(b == 1) {
int x = in.nextInt();
array[--h] = x;
}else {
h++;
}
}
}
while(h<=t) {
sb.append(array[h++]).append("\n");
}
h = 100101;
System.out.print(sb.toString());
}
}
}
