upload practice exam
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.mycompany.programmingquiz1_calebfontenot</groupId>
|
||||
<artifactId>ProgrammingQuiz1_CalebFontenot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<exec.mainClass>com.mycompany.programmingquiz1_calebfontenot.ProgrammingQuiz1_CalebFontenot</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 com.mycompany.programmingquiz1_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
* @param <T>
|
||||
*/
|
||||
public class DoubleLinkedListExam<T> {
|
||||
|
||||
Node<T> head;
|
||||
Node<T> tail;
|
||||
|
||||
class Node<T> {
|
||||
|
||||
T t;
|
||||
Node<T> l;
|
||||
Node<T> r;
|
||||
}
|
||||
|
||||
public T removeAt(int pos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
head = tail = null;
|
||||
}
|
||||
|
||||
public void addAt(T t, int pos) {
|
||||
System.out.println("Linked List size: " + this.size());
|
||||
if (pos == 0) { // add first element
|
||||
Node<T> newNode = new Node<T>();
|
||||
newNode.t = t;
|
||||
head = tail = newNode;
|
||||
return;
|
||||
}
|
||||
if (pos == this.size()) { // add at end
|
||||
Node<T> tmp = tail;
|
||||
Node<T> newNode = new Node<T>();
|
||||
newNode.t = t;
|
||||
tmp.r = newNode;
|
||||
newNode.l = tmp;
|
||||
newNode.r = null;
|
||||
tail = newNode;
|
||||
return;
|
||||
}
|
||||
if (pos < this.size()) { // add in middle
|
||||
Node<T> pointer = head;
|
||||
for (int i = 0; i < this.size() - 1; ++i) {
|
||||
pointer = pointer.r;
|
||||
}
|
||||
Node<T> newNode = new Node<T>();
|
||||
newNode.t = t;
|
||||
newNode.l = pointer;
|
||||
newNode.r = pointer.l;
|
||||
pointer.r = newNode;
|
||||
pointer.r.l = newNode;
|
||||
return;
|
||||
}
|
||||
if (pos < 0 || this.size() < pos) {
|
||||
throw new IndexOutOfBoundsException("Given index is outside the range of acceptible values.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int size() {
|
||||
Node<T> p = head;
|
||||
int count = 0;
|
||||
while (p != null) {
|
||||
count++;
|
||||
p = p.r;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "";
|
||||
Node<T> p = head;
|
||||
while (p != null) {
|
||||
s += p.t.toString() + " ";
|
||||
p = p.r;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
DoubleLinkedListExam<Integer> list = new DoubleLinkedListExam<>();
|
||||
list.addAt(10, 0);
|
||||
System.out.println(list);
|
||||
list.addAt(30, 1);
|
||||
list.addAt(20, 1);
|
||||
list.addAt(5, 0);
|
||||
|
||||
System.out.println(list);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 com.mycompany.programmingquiz1_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class InsertionSort {
|
||||
public static void insertionSort(String[] list)
|
||||
{
|
||||
int i = 1;
|
||||
while (i < list.length)
|
||||
{
|
||||
if (list[i - 1].compareTo(list[i]) >= 0) {
|
||||
String tmp = list[i - 1];
|
||||
list[i - 1] = list[i];
|
||||
list[i] = tmp;
|
||||
}
|
||||
++i;
|
||||
//1. Loop that opens the hole by shifting to the right
|
||||
|
||||
//2. End of loop of shifting ---Insert the current at the opened hole list[j+1]
|
||||
|
||||
}
|
||||
}
|
||||
public static void printArray(String[] array) {
|
||||
for (String current: array) {
|
||||
System.out.print(current + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
String[] array = {"Zedfrey", "Hello", "Glorious", "World"};
|
||||
printArray(array);
|
||||
insertionSort(array);
|
||||
printArray(array);
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
|
||||
*/
|
||||
|
||||
package com.mycompany.programmingquiz1_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class ProgrammingQuiz1_CalebFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Sun Dec 03 12:52:32 CST 2023
|
||||
artifactId=ProgrammingQuiz1_CalebFontenot
|
||||
groupId=com.mycompany.programmingquiz1_calebfontenot
|
||||
version=1.0-SNAPSHOT
|
@@ -0,0 +1,4 @@
|
||||
com/mycompany/programmingquiz1_calebfontenot/InsertionSort.class
|
||||
com/mycompany/programmingquiz1_calebfontenot/DoubleLinkedListExam.class
|
||||
com/mycompany/programmingquiz1_calebfontenot/ProgrammingQuiz1_CalebFontenot.class
|
||||
com/mycompany/programmingquiz1_calebfontenot/DoubleLinkedListExam$Node.class
|
@@ -0,0 +1,3 @@
|
||||
/home/caleb/ASDV-Java/Semester 3/Exams/Projects/ProgrammingQuiz1_CalebFontenot/src/main/java/com/mycompany/programmingquiz1_calebfontenot/ProgrammingQuiz1_CalebFontenot.java
|
||||
/home/caleb/ASDV-Java/Semester 3/Exams/Projects/ProgrammingQuiz1_CalebFontenot/src/main/java/com/mycompany/programmingquiz1_calebfontenot/InsertionSort.java
|
||||
/home/caleb/ASDV-Java/Semester 3/Exams/Projects/ProgrammingQuiz1_CalebFontenot/src/main/java/com/mycompany/programmingquiz1_calebfontenot/DoubleLinkedListExam.java
|
Reference in New Issue
Block a user