AiSD Kolejki i stosy


import java.io.*;
import java.util.*;


public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
do {
String[] line = sc.nextLine().split(" ");
switch(line.length) {
case 2:
ops(line[0], Integer.parseInt( line[1] ));
break;
case 3:
ops(line[0], Integer.parseInt( line[1] ), Integer.parseInt( line[2] ));
}

} while(sc.hasNext());

int i = 0, s = ar.size();
while(i < s)
System.out.println(ar.get(i++));
}

static void ops(String s1, int i) {
if(s1.equals("new_s"))
stacks[i] = new ArrayDeque();
else if(s1.equals("new_q"))
queues[i] = new ArrayDeque();
else if(s1.equals("pop"))
stacks[i].removeFirst();
else if(s1.equals("dequeue"))
queues[i].removeFirst();
else if(s1.equals("delete_q"));
else if(s1.equals("delete_s"));
else if(s1.equals("print_q"));
else if(s1.equals("print_s")) {
if(stacks[i].isEmpty())
ar.add("empty");
else {
String s = "";
Object[] tab = stacks[i].toArray();
for(int x = tab.length - 1; x >= 0; x--)
s += tab[x] + " ";
ar.add(s);
}
}
else if(s1.equals("delete_s"));
else if(s1.equals("delete_s"));
}

static void ops(String s1, int i, int j) {
if(s1.equals("push"))
stacks[i].addFirst(j);
if(s1.equals("enqueue"))
queues[i].addLast(j);
else if(s1.equals("stack->stack"))
stacks[j].addFirst(stacks[i].removeFirst());
else if(s1.equals("queue->queue"));
else if(s1.equals("queue->stack"));
else if(s1.equals("stack->queue"));

}

static Deque[] queues = new Deque[10];
static Deque[] stacks = new Deque[10];
static ArrayList ar = new ArrayList();
}


Wyszukiwarka

Podobne podstrony:
06 Stosy i kolejki
stosy,kolejki,drzewa
APP Stosy Kolejki Listy 11
APP Stosy Kolejki Listy
Stosy i kolejki
kolejkiFIFO(1)
AiSD w4 sortowanie2
KolejkiKomunikatow
AiSD Liczby Pierwsze
W9 Bezpieczne nastawy dla typowych obiektów AiSD
kolejkaJA
KolejkKomunikatow6
AiSD wyklad 2
AiSD Travelling Salesman Again !
SO2 instrukcja 4 Kolejki komunikatów
AiSD Problem Collatza
AiSD wyklad 7
AiSD Wyklad5 dzienne

więcej podobnych podstron