package pack;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Random;
public class Arrayuri implements KeyListener {
private Random r;
private boolean stop;
private long timp1,timp2,timp3;
private Integer[] array;
private LinkedList<Integer> link;
private HashSet<Integer> hash;
private ArrayList<Integer> listFrecv;
private int n;
public Arrayuri(int n){
timp1=0;
timp2=0;
timp3=0;
this.n=n;
stop=true;
r=new Random();
array=new Integer[3000];
link=new LinkedList<Integer>();
hash=new HashSet<Integer>();
listFrecv=new ArrayList<Integer>();
}
public void introducere(){
int i;
long t1,t2;
t1=System.currentTimeMillis();
System.out.println(t1);
for(i=0;i<n;i++)
{
array[i]=new Integer(r.nextInt());
}
t2=System.currentTimeMillis();
System.out.println(t2);
timp1=(t2-t1);
t1=System.currentTimeMillis();
for(i=0;i<n;i++)
{
link.add(new Integer(r.nextInt()));
}
t2=System.currentTimeMillis();
timp2=(t2-t1);
t1=System.currentTimeMillis();
for(i=0;i<n;i++)
{
hash.add(new Integer(r.nextInt()));
}
t2=System.currentTimeMillis();
timp3=(t2-t1);
}
public void rate() throws InterruptedException{
int i=0;
long t1 ,t2;
try{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String line=null;
System.out.println("Press any taste to stop");
while((line=in.readLine())==null){
t1=System.currentTimeMillis();
array[i++]=new Integer(r.nextInt());
t2=System.currentTimeMillis();
timp1+=(t2-t1);
t1=System.currentTimeMillis();
link.add(new Integer(r.nextInt()));
t2=System.currentTimeMillis();
timp2+=(t2-t1);
t1=System.currentTimeMillis();
hash.add(new Integer(r.nextInt()));
t2=System.currentTimeMillis();
timp3+=(t2-t1);
try{
Thread.sleep(200);
}catch(InterruptedException e){
System.out.println("Intrerupere");
}
}
}catch(Exception e){
System.out.println("Eroare la citire");
}
}
public void afisare(){
System.out.println("Timpul pt array: "+timp1);
System.out.println("Timpul pt LinkedList "+timp2);
System.out.println("Timpul pt HashSet "+timp3);
}
public void keyReleased(KeyEvent arg0) {
stop=false;
System.out.println("presed");
}
public void keyPressed(KeyEvent e) {
stop=false;
System.out.println("presed");
}
public void keyTyped(KeyEvent e) {
stop=false;
System.out.println("presed");
}
}
package pack;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
/**
* @param args
* @throws InterruptedException
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws InterruptedException {
try{
System.out.println("Introduceti nr:");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int n;
n=Integer.parseInt(in.readLine());
Arrayuri l=new Arrayuri(n);
l.introducere();
l.rate();
l.afisare();
}catch(IOException e){
System.out.println("Exceptie IO");
}catch(NumberFormatException e){
System.out.println("Format gresit");
}
}
}
Niciun comentariu:
Trimiteți un comentariu