From 71feb001f759282e7d0192f99c0ca3729963c241 Mon Sep 17 00:00:00 2001 From: Minkra <@> Date: Tue, 12 Dec 2023 12:06:25 +0100 Subject: [PATCH] 21. asan --- List.java | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 List.java diff --git a/List.java b/List.java new file mode 100644 index 0000000..23c144b --- /dev/null +++ b/List.java @@ -0,0 +1,90 @@ + +public class List +{ + private Node first; + + public List() { + first = null; + } + + public boolean isEmpty() { + if (first == null) return true; + return false; + } + + public int size() { + Node current = first; + int count = 0; + + while (current != null) { + count++; + current = current.next; + } + + return count; + } + + public T get(int n) { + Node current = first; + + for (int i = 0; i < n; i++) { + if (current == null) return null; + current = current.next; + } + + if (current == null) return null; + return current.wert; + } + + public void add(T val) { + Node neu = new Node(); + neu.wert = val; + + if (first == null) { + first = neu; + } else { + Node current = first; + while (current.next != null) { + current = current.next; + } + current.next = neu; + } + } + + public void add(int n, T val) { + if (n >=size()) { + add(val); + return; + } + Node neu = new Node(); + + neu.wert = val; + + if (n==0){ + neu.next = first; + first = neu; + return; + } + + for (int i = 0; i < n-1; i++){ + current = current.next; + } + neu.next = current.next; + current.next = neu; + + } + + public boolean contains(T val) { + Node current = first; + + while (current != null) { + if (current.wert.equals(val)) return true; + } + + return false; + } + + public T remove(int n) { + + } +}