Duvida Java

brunomelo

Power Member
Boas tenho uma duvida em java. Tenho k resolver um problema e pedem para criar uma lista e fila mas tendo em conta os tipos genéricos DList<E> e DQueue<E>

a minha duvida é como é que faço isto com o DLIST e o DQueue com listas normais sei como é assim nem por isso. Penso k tenho k fazer isto

public interface DList extends DCollection, java.util.List

alguem me ajuda?
 
DList é um tipo genérico que implementa o TDA Lista.
Penso que o DList é uma classe que já tem as operações das listas. acho que é isto :/
 
Penso que não é isto. Isto é de algoritmos e estruturas de dados e diz que o Dlist é um tipo genérico que implementa os TDA lista ja tou a fazer ***** coisa e penso que é como tinha dito.
 
Aqui tens algo para começar
(Já tenho saudades de fazer este tipo de coisas :D)

Código:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mypackage;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 *
 * @author Nuno
 */
public class TDACollection<T> implements Collection<T>, List<T> {

    private Class type;
    private T[] data;

    public TDACollection(Class type) {
        this.type = type;

        data = (T[]) Array.newInstance(type, 0);
    }

    public int size() {
        return data.length;
    }

    public boolean isEmpty() {
        return data.length == 0;
    }

    public Object[] toArray() {
        return data;
    }

    public <T> T[] toArray(T[] a) {
        return (T[]) Arrays.copyOf(data, a.length);
    }

    public boolean add(T e) {
        T[] newData = (T[]) Array.newInstance(type, data.length + 1);

        System.arraycopy(data, 0, newData, 0, data.length + 1);

        data = newData;

        return true;
    }

    public T get(int index) {
        return data[index];
    }

    public T set(int index, T element) {
        return (data[index] = element);
    }

    public boolean contains(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Iterator<T> iterator() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void add(int index, T element) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public T remove(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean remove(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean containsAll(Collection<?> c) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean addAll(Collection<? extends T> c) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean removeAll(Collection<?> c) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean retainAll(Collection<?> c) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void clear() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean addAll(int index, Collection<? extends T> c) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int indexOf(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int lastIndexOf(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public ListIterator<T> listIterator() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public ListIterator<T> listIterator(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public List<T> subList(int fromIndex, int toIndex) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
 
Back
Topo