Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
- //
- public class SimpleLinkedOrderedList<ELEMENT extends Comparable<ELEMENT>> extends SimpleLinkedList<ELEMENT> implements ILinkedOrderedList<ELEMENT> {
- //region Constructors
- public SimpleLinkedOrderedList() {
- super();
- }
- //endregion
- //region Ordered List Methods
- public void addInOrder(ELEMENT item) {
- if (this.size() == 0) {
- this.head = this.tail = new Node<ELEMENT>(item, null);
- ++this.count;
- }
- else {
- if (item.compareTo(this.head.item) <= 0) {
- this.addFirst(item);
- }
- else {
- if (item.compareTo(this.tail.item) > 0) {
- this.addLast(item);
- }
- else {
- Node<ELEMENT> skip = this.head;
- while ((skip != null) && (skip.next != null) && (item.compareTo(skip.next.item) > 0)) {
- skip = skip.next;
- }
- if (skip == null) {
- throw new RuntimeException("Algo está mal en el orden de los elementos de la lista...");
- }
- else {
- Node<ELEMENT> temp = new Node<ELEMENT>(item, skip.next);
- skip.next = temp;
- ++this.count;
- }
- }
- }
- }
- }
- // public boolean findAndRemove(ELEMENT item) {
- // if (this.size() == 0) {
- // return false;
- // }
- //
- // DoubleLinkedList.Node<ELEMENT> skip = this.head;
- // while ((skip != null) && !(item.compareTo(skip.item) == 0)) {
- // skip = skip.next;
- // }
- // if (skip == null) {
- // return false;
- // }
- // else {
- // if (skip.prev == null) {
- // this.removeFirst();
- // return true;
- // }
- // else {
- // if (skip.next == null) {
- // this.removeLast();
- // return true;
- // }
- // else {
- // skip.prev.next = skip.next;
- // skip.next.prev = skip.prev;
- // skip.prev = skip.next = null;
- // return true;
- // }
- // }
- // }
- // }
- //endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement