From 643bdc658f2f742e1a305046f675e42d82385007 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Fri, 3 Nov 2023 13:33:29 -0500 Subject: [PATCH] CircularList --- .gitignore | 1 + .../Assignments/MP6_CalebFontenot/pom.xml | 14 ++ .../caleb/mp6_calebfontenot/CircularList.java | 139 ++++++++++++++++++ .../mp6_calebfontenot/DoubleLinkedList.java | 87 +++++++++++ .../mp6_calebfontenot/MP6_CalebFontenot.java | 16 ++ 5 files changed, 257 insertions(+) create mode 100644 Semester 3/Assignments/MP6_CalebFontenot/pom.xml create mode 100644 Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/CircularList.java create mode 100644 Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/DoubleLinkedList.java create mode 100644 Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/MP6_CalebFontenot.java diff --git a/.gitignore b/.gitignore index fb9a6bf..ca7b1f2 100644 --- a/.gitignore +++ b/.gitignore @@ -192,3 +192,4 @@ /Semester 3/Assignments/TestHashCode/build/ /Semester 3/Assignments/LinkedList/nbproject/private/ /Semester 3/Assignments/LinkedList/build/ +/Semester 3/Assignments/MP6_CalebFontenot/target/ diff --git a/Semester 3/Assignments/MP6_CalebFontenot/pom.xml b/Semester 3/Assignments/MP6_CalebFontenot/pom.xml new file mode 100644 index 0000000..9248097 --- /dev/null +++ b/Semester 3/Assignments/MP6_CalebFontenot/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + edu.slcc.asdv.caleb + MP6_CalebFontenot + 1.0-SNAPSHOT + jar + + UTF-8 + 20 + 20 + edu.slcc.asdv.caleb.mp6_calebfontenot.MP6_CalebFontenot + + \ No newline at end of file diff --git a/Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/CircularList.java b/Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/CircularList.java new file mode 100644 index 0000000..c7f858d --- /dev/null +++ b/Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/CircularList.java @@ -0,0 +1,139 @@ +package edu.slcc.asdv.caleb.mp6_calebfontenot; + +/** + * + * @author Markou + */ +public class CircularList> { + + Node head; + + public class Node< T extends Comparable> + implements Comparable> { + + private T t; + + public void set(T t) + { + this.t = t; + } + + public T get() + { + return t; + } + Node next; + + @Override + public int compareTo(Node o) + { + return this.t.compareTo(o.get()); + } + } + + /** + * + * @param t + */ + public void add(Object t) + { + Node temp = new Node(); + temp.set((T) t); + + if (head == null) { + head = temp; + head.next = head; + } else { + Node temp2 = head; + do { + temp2 = temp2.next; + } while (temp2.next != head); + temp.next = head; + temp2.next = temp; + } + } + + /** + * + * @return + */ + private int getSize() + { + if (head == null) { + return 0; + } + Node temp = head; + int count = 0; + do { + temp = temp.next; + count++; + } while (temp != head); + + return count; + } + //////////////////////////////////////////////////////// + + public void addAt(Object t, int pos) + { + if (pos < 0 || pos > getSize()) { + return; + } + + Node temp = new Node(); + temp.set((T) t); + + if (head == null) { + add(t); + } else if (pos == 0) { + + } else { + + } + } +////////////////////////////////////////////////////////////// +/** + * removes the + */ + public void remove() + { + + } +////////////////////////////////////////////////////////////// +/** + * removes a specific object from the list + */ + public boolean remove(Object t) + { + return true; + } +////////////////////////////////////////////////////////////// + + public void removeAt(int pos) + { + + } + + public void print() + { + + if (head == null) { + return; + } + Node temp = head; + do { + System.out.println(temp.get().toString()); + temp = temp.next; + } while (temp != head); + + } + + public static void main(String... ar) + { + CircularList list = new CircularList(); + list.add("Hello"); + list.add("World"); + list.print(); + + } + +} diff --git a/Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/DoubleLinkedList.java b/Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/DoubleLinkedList.java new file mode 100644 index 0000000..b3359c7 --- /dev/null +++ b/Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/DoubleLinkedList.java @@ -0,0 +1,87 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package edu.slcc.asdv.caleb.mp6_calebfontenot; + +/** + * + * @author caleb + */ +public class DoubleLinkedList { + Node head; + Node tail; + + class Node { + T t; + Node left; + Node right; + } + + public void addAt(T t, int pos) { + if (pos < 0 || pos > size()) { + throw new IndexOutOfBoundsException(); + } + Node newNode = new Node(); + newNode.t = t; + if (head == null) { // list is empty + head = tail = newNode; + } else if (pos == 0) { // add at the front + newNode.right = head; + head.left = newNode; + head = newNode; + } else if (pos == size()) {// add at the end + newNode.left = tail; + tail.right = newNode; + tail = newNode; + } else { //We're in the middle + Node p = head; + for (int i = 0; i < pos - 1; ++i) { + p = p.right; + } + newNode.left = p; + newNode.right = p.right; + p.right.left = newNode; + } + } + public int size() { + Node p = head; + int count = 0; + while (p != null) { + count++; + p = p.right; + } + return count; + } + + @Override + public String toString() + { + String outputString = "DoubleLinkedList{" + "head=" + head + ", tail=" + tail +", size=" + this.size() + "}\n Contents= ["; + Node p = head; + int count = 0; + while (p != null) { + outputString += p.t.toString(); + if (count -1 < size()) { + outputString += ", "; + } else { + outputString += "]"; + } + p = p.right; + count++; + } + return outputString; + } + + public static void main(String[] args) + { + DoubleLinkedList list = new DoubleLinkedList<>(); + list.addAt(10, 0); + list.addAt(20, 0); + list.addAt(30, 0); + list.addAt(40, 0); + list.addAt(40, 3); + list.addAt(25, 3); + System.out.println(list); + } +} diff --git a/Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/MP6_CalebFontenot.java b/Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/MP6_CalebFontenot.java new file mode 100644 index 0000000..c5b912d --- /dev/null +++ b/Semester 3/Assignments/MP6_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp6_calebfontenot/MP6_CalebFontenot.java @@ -0,0 +1,16 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package edu.slcc.asdv.caleb.mp6_calebfontenot; + +/** + * + * @author caleb + */ +public class MP6_CalebFontenot { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } +}