Jump to content

Recommended Posts

Posted

Boas tenho uma duvida em relação a uma implementação de listas duplamente ligadas.

É o seguinte tenho duas listas ex:

1 2 3 4 3 1

9 9 1 4 5 7

Objectivo: armazenar as duas listas.

tenho este for para adicionar à lista

for(int i=0; i<lista.length;i++){
 lista.addEnd(Integer.parseInt(list1[i]), Integer.parseInt(list2[i]));
}

E no addEnd estou a utilizar dois heads (talvez não seja o mais apropriado)

Node i = head1;
Node p = head2;
while (i.next != null) {
 i = i.next;
 p = p.next;
}

i.next = new Node(a, null);
p.next = new Node(b, null);
}
}

E esta class Node

private class Node {
 private int element;
 private Node next;

 private Node(int element, Node next) {
   this.element = element;
   this.next = next;

 }
}
}
}

Será que esta é a maneira mais indicada de o fazer ?

Agradeço todas a observações.

P.S: o codigo não está todo postado, só apenas as partes a melhorar.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.