Advertisement
Montoya-Romina-Anahi

Tp4(7)ListaEquipo

Jul 7th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. import java.util.LinkedList;
  2.  
  3.  
  4. public class ListaEquipo {
  5. private class Node {
  6. public Equipo item;
  7. public Node next;
  8. public Node prev;
  9.  
  10.  
  11.  
  12. public Node(Equipo temp2, Node next) {
  13. this.item = temp2;
  14. this.next = next;
  15. }
  16.  
  17. @Override
  18. public String toString() {
  19. return this.item.toString();
  20. }
  21. }
  22.  
  23. private Node head;
  24. private int count;
  25. private Node tail;
  26.  
  27. public int size() {
  28. return this.count;
  29. }
  30.  
  31. public ListaEquipo() {
  32. this.head = null;
  33. this.count = 0;
  34. this.tail = null;
  35. }
  36.  
  37. public void addFirstRookieVersion(Equipo item) {
  38. if (this.count == 0) {
  39. this.head = this.tail = new Node(item, null);
  40. ++this.count;
  41. } else {
  42. Node temp = new Node(item, null);
  43. temp.next = this.head;
  44. this.head = temp;
  45. ++this.count;
  46. }
  47. }
  48. public void addFirst(Equipo temp2) {
  49. Node temp = new Node(temp2, this.head);
  50. if (this.count == 0) {
  51. this.tail = temp;
  52. }
  53. this.head = temp;
  54. ++this.count;
  55. }
  56.  
  57. public void addLastRookieVersion(Equipo item) {
  58. if (this.count == 0) {
  59. this.head = this.tail = new Node(item, null);
  60. ++this.count;
  61. } else {
  62. Node temp = new Node(item, null);
  63. this.tail.next = temp;
  64. this.tail = temp;
  65. ++this.count;
  66. }
  67. }
  68. public void addLast(Equipo item) {
  69. Node temp = new Node(item, null);
  70. if (this.count == 0) {
  71. this.head = temp;
  72. } else {
  73. this.tail.next = temp;
  74. }
  75. this.tail = temp;
  76. ++this.count;
  77. }
  78.  
  79. public Equipo removeFirst() {
  80. if (this.count == 0) {
  81. throw new RuntimeException("La lista esta vacia...");
  82. }
  83. Equipo item = this.head.item;
  84. this.head = this.head.next;
  85. if (this.head == null) {
  86. this.tail = null;
  87. }
  88. --this.count;
  89. return item;
  90. }
  91.  
  92. public Equipo removeLast() {
  93. if (this.count == 0) {
  94. throw new RuntimeException("La lista esta vacia...");
  95. }
  96. Equipo item = this.tail.item;
  97. if (this.head.next == null) {
  98. this.head = this.tail = null;
  99. } else {
  100. Node skip = this.head;
  101. while (skip.next.next != null) {
  102. skip = skip.next;
  103. }
  104. this.tail = skip;
  105. this.tail.next = null;
  106. }
  107. --this.count;
  108. return item;
  109. }
  110.  
  111. public void Mostrar() {
  112. for (Node skip = this.head; skip != null; skip = skip.next) {
  113. System.out.printf("%s ", skip.item.toString());
  114. }
  115. System.out.println();
  116. }
  117.  
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement