코드비교

Old VersionNew Version
1 1 
2class Queue { 2class Queue { 
3int[] elements = new int[1000000]; 3int []elements=new int[1000];
4static int size = 0; 4int a,size=0;
5Queue() { 5void enqueue(int v) {
6size = 8; 6for(a=size;a>0;a--) {
   7elements[a]=elements[a-1];
7} 8} 
8void enqueue(int x) { 8elements[0]=v;
9elements[size] = x;   
10size++; 10size++; 
11} 11} 
12int dequeue() { 12int dequeue() { 
13for(int i=0; i<size-1; i++) { 13return elements[--size];
14elements[i] = elements[i+1];   
15}   
16size--;   
17return elements[7];   
18} 14} 
19boolean empty() { 15boolean empty() { 
20if(size==8) return true; 20if(size==0)return true;
21else return false; 17else return false; 
22} 18} 
23int getSize() {   
24return size;   
25} 19} 
26}   

sample code

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Queue queue = new Queue();
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for (int i = 0; i < N; i++) {
int n = sc.nextInt();
if (n == -1) {
if (!queue.empty()) queue.dequeue();
} else {
queue.enqueue(n);
}
}
while (!queue.empty())
System.out.println(queue.dequeue());
}
}
class Queue {
int[] elements = new int[1000000];
static int size = 0;
Queue() {
size = 8;
}
void enqueue(int x) {
elements[size] = x;
size++;
}
int dequeue() {
for(int i=0; i<size-1; i++) {
elements[i] = elements[i+1];
}
size--;
return elements[7];
}
boolean empty() {
if(size==8) return true;
else return false;
}
int getSize() {
return size;
}
}
class Queue {
int []elements=new int[1000];
int a,size=0;
void enqueue(int v) {
for(a=size;a>0;a--) {
elements[a]=elements[a-1];
}
elements[0]=v;
size++;
}
int dequeue() {
return elements[--size];
}
boolean empty() {
if(size==0)return true;
else return false;
}
}