Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# data-strucutures-java
Data Structures implemented in Java.
This project will evolve with future improvments in the DS implementation, test coverage and code quality.
This project will evolve with future improvments in the DS implementation, test coverage and code quality so be with us. We will bring more solutions, sloved problems on data structure using java. Thank you.
19 changes: 10 additions & 9 deletions src/main/java/com/leonardoz/datastructures/SimplyLinkedList.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.leonardoz.datastructures;

public class SimplyLinkedList<E> implements LinkedList<E> {


// class to create a node of the linked list.
static class Node<E> {
E value = null;
Node<E> next = null;
Expand Down Expand Up @@ -35,7 +36,7 @@ public void insert(E value) {
size++;
}

// inserting the given 'value' at the given 'position'.
@Override
public void insertAt(E value, int position) throws IllegalArgumentException {
if (position > size) {
Expand All @@ -62,7 +63,7 @@ public void insertAt(E value, int position) throws IllegalArgumentException {
size++;
}

// remove value from the given position of a linked list.
@Override
public E removeAt(int position) throws IllegalArgumentException {
if (position > size) {
Expand All @@ -75,7 +76,7 @@ public E removeAt(int position) throws IllegalArgumentException {
first = first.next;
return aux.value;
} else if (position == (size - 1)) {
// recupera o previous ao �ltimo
// recupera o previous ao último
Node<E> Node = getNode(position - 1);
Node.next = null;
Node<E> aux = last;
Expand All @@ -88,15 +89,15 @@ public E removeAt(int position) throws IllegalArgumentException {
return removed.value;
}
}
// returns the element from the given position.
@Override
public E getAt(int position) throws IllegalArgumentException {
if (position > size) {
throw new IllegalArgumentException("Illegal position. ");
}
return getNode(position).value;
}
// returns the node of the given position
private Node<E> getNode(int position) {
if (position == 0) {
return first;
Expand All @@ -112,17 +113,17 @@ private Node<E> getNode(int position) {
return aux;
}
}

// returns the first element of the linked list.
@Override
public E getFirst() {
return first.value;
}
// returns the last elemetn of the linked list.
@Override
public E getLast() {
return last.value;
}
// returns the total number of nodes or length of the linked list.
@Override
public int getSize() {
return size;
Expand Down