duminică, 2 septembrie 2012

Timer 3-structuri de date.c


package cs.timer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Fir extends Thread{

private Integer a;

public Fir(Integer a) {

super();
this.a=a;
}

public void run() {

BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));

try {
stdin.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

this.a=new Integer(2);
}
}
package cs.timer;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class Test {

private Random generator;

private Fir fir;
private volatile Integer a;
private Integer[] array;
private List<Integer> list;
private HashSet<Integer> hashSet;
private ArrayList<Integer> listaAux;
private int n;

private long addT1;
private long addT2;
private long addT3;

private long remT1;
private long remT2;
private long remT3;

public Test() {

this.a=new Integer(0);
this.addT1 = 0;
this.addT2 = 0;
this.addT3 = 0;

this.remT1 = 0;
this.remT1 = 0;
this.remT1 = 0;

this.n = new Integer(3000);
this.array = new Integer[3000];
this.list = new LinkedList<Integer>();
this.hashSet = new HashSet<Integer>();
this.generator = new Random();
this.listaAux = new ArrayList<Integer>();
}

public void golireVector(int n) {

while (n > 0) {

this.array[this.generator.nextInt(n)] = this.array[this.n - 1];
--n;
}
}

public void golireLista() {

while (!this.list.isEmpty()) {

this.list.remove(this.generator.nextInt(this.list.size()));
}
}

public void golireHas() {

while (!this.hashSet.isEmpty()) {

this.hashSet.remove(new Integer(this.generator.nextInt()));
}
}

public void insert(int n) {

int i;
long t1, t2;

for (i = 0; i < n; ++i) {

t1 = System.currentTimeMillis();
this.array[i] = new Integer(this.generator.nextInt());
t2 = System.currentTimeMillis();

this.addT1 += (t2 - t1);

t1 = System.currentTimeMillis();
this.list.add(new Integer(this.generator.nextInt()));
t2 = System.currentTimeMillis();

this.addT2 += (t2 - t1);

t1 = System.currentTimeMillis();
this.hashSet.add(new Integer(this.generator.nextInt()));
t2 = System.currentTimeMillis();

this.addT3 += (t2 - t1);
}
}

public void insertRate() {

int i;
long t1, t2;
Integer a;
for (i = 0; i < this.listaAux.size(); ++i) {

a=this.listaAux.get(i);
t1 = System.currentTimeMillis();
this.array[i] = new Integer(a);
t2 = System.currentTimeMillis();
this.addT1 += (t2 - t1);
t1 = System.currentTimeMillis();
this.list.add(a);
t2 = System.currentTimeMillis();
this.addT2 += (t2 - t1);
t1 = System.currentTimeMillis();
this.hashSet.add(a);
t2 = System.currentTimeMillis();
this.addT3 += (t2 - t1);
}

}
public static void main(String[] args) {
Test test=new Test();
}

public void doSomething() {
System.out.println("Citire nr elemente:");
}
}

Niciun comentariu:

Trimiteți un comentariu