Escolar Documentos
Profissional Documentos
Cultura Documentos
1.
HillClimbing
Offline
Posts: 40
Abraço!
1.
joaotacio
Offline
Posts: 32
Pegue uma folha e uma lápis, escreva o nome dos nodos e os valores
iniciais. Fica mais fácil de entender.
aux=pri
ant=null
entao aux=Brasil
ant=null
_________________
JavaFree.org
1.
gerasampagode
Offline
Posts: 2
EvertonJoseBenedicto_0510
Baixar:
688_Lista.zip
Taman
1 KB
ho:
_________________
Everton
MSN: gerasampagode@hotmail.com
e-mail: blmad@walla.com
1.
gerasampagode
Offline
Posts: 2
1.
bodao
Offline
Posts: 1
1. package ListaDuplaEncadeada;
2.
3. /** Implementação da estrutura de dados NODE ****/
4. public class Node {
5.
6. int info;
7.
8. Node prox;
9.
10. Node ante;
11.
12. public Node(int valor) {
13. this.info = valor;
14. this.prox = null;
15. this.ante=null;
16.
17. }
18. }/** ***Fim da Classe No*****/
1. package ListaDuplaEncadeada;
2.
3. public class List {
4. Node i;
5.
6. public List() {
7. this.i = null;
8.
9. }
10.
11. public void insereInicio(int valor) {
12. if (this.i == null)
13. this.i = new Node(valor);
14. else {
15. Node temp = new Node(valor);// cria um atributo temporario do tipo
16. // Node
17.
18. temp.prox = this.i; // o prox recebe as informações do no do começo
19. this.i = temp;
20. /**
21. * o novo no toma o lugar do no anterior, ja que o a informação do
22. * no ini foi afastada
23. */
24.
25. }// *** Fim da inserção pelo inicio ******/
26. }
27.
28. public String info() {
29. String x;
30. if (this.i == null)
31. return ("Lista Vazia");
32. else {
33. Node temp = this.i;
34. x = ""; // inicia o atributo com string ""
35. while (temp != null) {
36. x = x + " , " + temp.info;
37. /** Faz a concatenação com a String * */
38. temp = temp.prox;
39. /** * Parte para o proximo * */
40. }
41. return (x);
42. }
43. }
44.
45. public String removeInicio() {
46. String temp = "";
47.
48. if (this.i == null)
49. return ("Lista Vazia");
50. else {
51. temp = "" + this.i.info;
52. i = this.i.prox;
53. return temp;
54. }
55. }
56.
57. /** Fim do metodo remover do inicio ** */
58.
59. public int quantNo() {
60. Node temp = this.i;
61. /** Atribui o Nó i no atributo temporario temp * */
62. int c = 0;
63. /** atributo auxiliar * */
64. while (temp != null) {
65. c = c++;
66. /** incremento * */
67. temp = temp.prox;
68. /** passa para o proximo nó * */
69. }
70. return c;
71. /** Retorna a quantidade de nó que tem a lista * */
72. }
73.
74. /** Fim do metodo quantNo * */
75.
76. public void insereNoFinal(int valor) {
77. if (this.i == null)
78. this.i = new Node(valor);
79. else {
80. Node aux = this.i;
81. /** Laço para caminhar pela lista ** */
82. while (aux.prox != null) {
83. aux = aux.prox;
84. }
85. Node p = new Node(valor);
86. /** atributo auxiliar * */
87. aux.prox = p;
88. /** inserindo no proximo no depois do nó aux * */
89.
90. }
91. /** fim do metodo Inserir no final * */
92. }
93.
94. public String removeDoFim() {
95. String removido = null; /** Inicialização do atributo do tipo String **/
96. if (this.i == null)
97. return ("Lista Vazia");
98. else {
99. /** Percorre a lista até achar o final da lista **/
100. while (this.i.prox != null) {
101. this.i = this.i.prox;
102. }
103. removido = "" + this.i.info; /** pega a info do nó anterior a
i.prox ***/
104.
105. this.i=null;
106.
107.
108.
109. return (removido);
110.
111. }
112.
113. }
114. public String topo(){
115. String resp=null;
116. if( this.i==null)
117. return("Lista Vazia");
118. else
119. resp=""+this.i.info;
120. return(resp);
121.
122.
123. }
124. }
1. public class Fila {
2.
3. List x=null;
4.
5. public Fila(){
6. x=new List();
7. }
8.
9. public boolean filaVazia(){
10. if(this.x==null)
11.
12. return(true);
13. else
14. return(false);
15.
16. }
17. public void inserir(int valor){
18. x.insereInicio(valor);
19. }
20.
21. public String remover(){
22. String aux=null;
23. aux=x.removeDoFim();
24. return(aux);
25. }
26. public String top(){
27. String y=null;
28. y=x.topo();
29. return y;
30. }
31.
32.
33. }
e a classe de teste
1. package ListaDuplaEncadeada;
2.
3. public class testeMain {
4.
5.
6. public static void main(String[] args) {
7.
8.
9. Pilha x = new Pilha();
10. Fila y =new Fila();
11.
12. x.pop(4);
13. x.pop(5);
14. x.pop(8);
15.
16. String t,r,z =null;
17.
18. t=x.push();
19. r=x.push();
20. String o= x.topo();
21.
22.
23. System.out.println("1° push ="+ t+" " + "topo="+ o +"\n" +"2° push="+r);
24.
25.
26. String w,k,l,b=null;
27. y.inserir(10);
28. y.inserir(11);
29. y.inserir(12);
30.
31. w=y.remover();
32. k=y.remover();
33. l=y.remover();
34. b=y.top();
35.
36.
37. System.out.println("primeira remoção="+w + "\n"+"segunda remoção="+k +"\
n"+"terceira remoção="+l+"\n"+"topo da fila="+ b);
38.
39.
40. }
41.
42. }
com o teste da pilha dá tudo ok, mas no da fila nao consigo remover =/, alguem poderia me
ajudar?
1.
Relacionados
Bingo Urgente!!!!!!!!!!!!!!!!!!
http://javafree.uol.com.br/topic-865527-Bingo-Urgente.html
Lista de Sessões
http://javafree.uol.com.br/topic-855173-Lista-de-Sessoes.html