Initial commit

This commit is contained in:
2022-10-09 06:19:03 +03:30
commit bf2ab28205
27 changed files with 710 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
package com.tabrizu.ds;
/**
* Hello world!
*/
public final class App {
private App() {
}
/**
* Says hello to the world.
* @param args The arguments of the program.
*/
public static void main(String[] args) {
System.out.println("Hello World!");
SingleLinkedList<Integer> myList = new SingleLinkedList<Integer>();
}
}
@@ -0,0 +1,12 @@
package com.tabrizu.ds;
public interface ISingleLinkedList<T> {
public int size();
public void addFirst(T value);
public void addLast(T value);
public T removeFirst();
public T removeLast();
public T getFirst();
public T getLast();
}
@@ -0,0 +1,106 @@
package com.tabrizu.ds;
public class SingleLinkedList<T> implements ISingleLinkedList<T> {
private class Node {
private T m_value;
private Node m_next;
public Node(T value, Node next) {
m_value = value;
m_next = next;
}
public T getValue() {
return m_value;
}
public Node getNext() {
return m_next;
}
public void setNext(Node next) {
m_next = next;
}
}
private Node m_head;
private Node m_tail;
private int m_size;
public SingleLinkedList() {
m_head = null;
m_tail = null;
m_size = 0;
}
@Override
public int size() {
return m_size;
}
@Override
public void addFirst(T value) {
m_head = new Node(value, m_head);
if (m_size == 0) {
m_tail = m_head;
}
m_size += 1;
}
@Override
public void addLast(T value) {
if (m_size == 0) {
addFirst(value);
}
Node newNode = new Node(value, null);
m_tail.setNext(newNode);
m_tail = newNode;
m_size++;
}
@Override
public T removeFirst() {
if (m_size == 0) {
return null;
}
T lastHead = m_head.getValue();
m_head = m_head.getNext();
m_size--;
return lastHead;
}
@Override
public T removeLast() {
if (m_size == 0) {
return null;
}
T lastTail = m_tail.getValue();
Node currentNode = m_head;
while (currentNode.getNext() != null){
currentNode = currentNode.getNext();
}
}
@Override
public T getFirst() {
// TODO Auto-generated method stub
return null;
}
@Override
public T getLast() {
// TODO Auto-generated method stub
return null;
}
@Override
public String toString() {
}
}
@@ -0,0 +1,18 @@
package com.tabrizu.ds;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Unit test for simple App.
*/
class AppTest {
/**
* Rigorous Test.
*/
@Test
void testApp() {
assertEquals(1, 1);
}
}