Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3b57149
Shell sort
Mar 23, 2017
d5fd3dd
Shell sort
Mar 23, 2017
b73a9c8
Shell Sort Done
Apr 4, 2017
697849b
Changes to GUI to make more options for sorting arrays and allows
Apr 4, 2017
cc45b99
Adds comb sort to the list of sorting alorithms. Also changes the gui a
Apr 4, 2017
8bbd201
Adds radix sort with some minor code fixes
Apr 7, 2017
6cf8f09
Added cocktail shaker sort, gnome sort with a bubble sort variation and
Apr 7, 2017
1e34a4e
Added cocktail shaker sort, gnome sort with a bubble sort variation and
Apr 8, 2017
ac93c5d
Started working on a graphics representation for the sorting. This is a
Apr 11, 2017
2c7f799
Changed more GUI stuff. Creates a visualization for the random array
anthonymonti2 Apr 11, 2017
018bab8
Started working on a graphics representation for the sorting. This is a
Apr 11, 2017
ab18518
Graphical changes
Apr 13, 2017
b14ec90
Selection sort graphics works
anthonymonti2 Apr 13, 2017
660266f
Shell sort vis works but no colors
anthonymonti2 Apr 13, 2017
b403698
Graphical changes
Apr 13, 2017
cc6e61b
Graphical changes
Apr 14, 2017
66010c8
Graphical changes
Apr 14, 2017
1a28fcc
Graphical changes
Apr 15, 2017
6a24f9f
Added a selection menu to the gui and some buttons
anthonymonti2 Apr 15, 2017
f18619a
Added a selection menu to the gui and some buttons
anthonymonti2 Apr 17, 2017
465d46c
Added a selection menu to the gui and some buttons
anthonymonti2 Apr 17, 2017
7386d46
Added a selection menu to the gui and some buttons
anthonymonti2 Apr 17, 2017
1b6daf2
Apr 17, 2017
a21eb68
Added a selection menu to the gui and some buttons
anthonymonti2 Apr 17, 2017
c24dcc7
Added a selection menu to the gui and some buttons
anthonymonti2 Apr 19, 2017
4c7bd27
Added a selection menu to the gui and some buttons
anthonymonti2 Apr 19, 2017
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
270 changes: 270 additions & 0 deletions DSFinal/hs_err_pid7124.log

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion DSFinal/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=dsfinal.DSFinal
main.class=dsfinal.FinalProjectNB
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
Expand Down
1,362 changes: 1,362 additions & 0 deletions DSFinal/replay_pid7124.log

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions DSFinal/src/dsfinal/Block.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dsfinal;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

/**
*
* @author Anthony
*/
public class Block extends Rectangle {

final int blockMulti = 10;

public Color color;
protected boolean isSorted;
protected int value;

public Block(int x, int y, int w, int value, Color c,boolean iS)
{
super(x,y,w,value);
this.color = c;
isSorted = iS;
this.value = value;
}

public void drawBlock(Graphics g)
{
g.setColor(color);
//g.drawRect(super.x, super.y - (value * blockMulti), super.width, (value * blockMulti));
g.fillRect(super.x, super.y - (value * blockMulti), super.width, (value * blockMulti));
g.drawString(addZero(value), x+ 6, y + 20);
}

public String addZero(int num)
{
if(num < 10)
{
return "0" + num;
}
else
{
return num + "";
}
}

}
10 changes: 7 additions & 3 deletions DSFinal/src/dsfinal/BubbleSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
*
* @author Anthony
*/
public class BubbleSort extends SortingUtils implements Runnable {
public class BubbleSort extends SortingUtils {

public BubbleSort(int[] array)
public BubbleSort(int[] array, boolean isGraphic)
{
super(array,"Bubble Sort");
super(array,"Bubble Sort",isGraphic);
}

@Override
Expand All @@ -36,4 +36,8 @@ public void run()
super.run();
}

public void stepSort()
{
}

}
161 changes: 161 additions & 0 deletions DSFinal/src/dsfinal/CocktailShakerSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dsfinal;

import java.awt.Color;
import java.awt.Graphics;

/**
*
* @author anthnoym
*/
public class CocktailShakerSort extends SortingUtils{

protected int iNum;
protected int iNumTwo;
protected boolean swappedBol;
protected int loops;
protected boolean running;
protected boolean sorted;

public CocktailShakerSort(int[] array, boolean isGraphic)
{
super(array, "Cocktail Shaker Sort", isGraphic);

if(isGraphic)
{
swappedBol = false;
iNum = 0;
iNumTwo = blockArray.length - 2;
loops = 0;
running = true;
sorted = false;
}
}

public void sort()
{
boolean swapped = false;
do
{
swapped = false;

for(int i = 0; i < array.length-2; i++)
{
if(array[i] > array[i+1])
{
swap(i, i+1);
swapped = true;
}
}

if(!swapped)
{
break; //already sorted
}

swapped = false;

for(int i = array.length - 2; i > 0; i--)
{
if(array[i] > array[i+1])
{
swap(i, i+1);
swapped = true;
}
}
}
while(swapped);

}

public void stepSort()
{
if(running)
{
if(iNum < blockArray.length - 2)
{
for (Block blockArray1 : blockArray) {
if (blockArray1.isSorted) {
blockArray1.color = Color.ORANGE;
} else {
blockArray1.color = Color.green;
}
}
blockArray[iNum].color = Color.RED;
blockArray[iNum + 1].color = Color.RED;

if(blockArray[iNum].value > blockArray[iNum + 1].value)
{
blockArray[iNum].color = Color.BLUE;
blockArray[iNum + 1].color = Color.BLUE;
swapGraphic(iNum, iNum + 1);
swappedBol = true;
//System.out.println("Swap forward");
}
iNum++;
}

if(iNum >= blockArray.length - 2-loops)
{
if(iNumTwo <= blockArray.length - 2)
swappedBol = false;

if(iNumTwo > 0)
{
for (Block blockArray1 : blockArray) {
if (blockArray1.isSorted) {
blockArray1.color = Color.ORANGE;
} else {
blockArray1.color = Color.green;
}
}

blockArray[iNumTwo].color = Color.RED;
blockArray[iNumTwo + 1].color = Color.RED;

if(blockArray[iNumTwo].value > blockArray[iNumTwo + 1].value)
{
blockArray[iNumTwo].color = Color.BLUE;
blockArray[iNumTwo + 1].color = Color.BLUE;
swapGraphic(iNumTwo, iNumTwo + 1);
swappedBol = true;
}
iNumTwo--;
}
}

if(iNumTwo <= 0 + loops)
{
if(swappedBol == false && iNum <= blockArray.length - 2 - loops && iNumTwo >= 0 + loops)
{
running = false;
blockArray[iNum+1].color = Color.YELLOW;
blockArray[iNumTwo+2].color = Color.YELLOW;
}

blockArray[iNum+1-loops].isSorted = true;
blockArray[iNumTwo].isSorted = true;

iNum = loops;
iNumTwo = blockArray.length - 2 - loops;
loops++;


swappedBol = false;
}
}
else
{
//System.out.println("Already sorted");
}
}
public void run()
{
super.run();
//System.out.println(super.toString());
}
}
130 changes: 130 additions & 0 deletions DSFinal/src/dsfinal/CombSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dsfinal;

import java.awt.Color;

/**
*
* @author anthnoym
*/
public class CombSort extends SortingUtils
{
protected int gapNum;
protected boolean sortedBol;
protected int iNum;
final double shrink = 1.3;
protected boolean finishedLoop;
protected int qNum;
protected int numZero;

public CombSort(int[] array, boolean isGraphic)
{
super(array, "Comb Sort", isGraphic);

if(isGraphic)
{
gapNum = blockArray.length;
gapNum = (int)(gapNum/shrink);
sortedBol = false;
iNum = 0;
qNum = 0;
numZero = 0;
finishedLoop = false;
}
}

public void sort()
{
int gap = array.length;
boolean sorted = false;

while(!sorted)
{
gap = (int)(gap/shrink);
if(gap > 1)
{
sorted = false;
}
else
{
gap = 1;
sorted = true;
}

for(int i = 0; i + gap < array.length; i++)
{
if(array[i] > array[i+gap])
{
swap(i,i+gap);
sorted = false;
}
}
}
}

public void run()
{
super.run();
}

public void stepSort()
{
if(gapNum > -1)
{
for(int i = 0; i < blockArray.length; i++)
{
blockArray[i].color = Color.green;
}

if(iNum + gapNum < blockArray.length)
{
blockArray[iNum].color = Color.RED;
blockArray[iNum+gapNum].color = Color.RED;

if(blockArray[iNum].value > blockArray[iNum+gapNum].value)
{
blockArray[iNum].color = Color.BLUE;
blockArray[iNum + gapNum].color = Color.BLUE;
swapGraphic(iNum, iNum+gapNum);
sortedBol = false;
}
iNum++;
}
else
{
iNum = 0;
gapNum = (int)(gapNum/shrink);

if(gapNum == 0)
{
gapNum = 1;
numZero++;
}
if(numZero > 1)
{
gapNum = -1;
sortedBol = true;
}

}




}
else
{
if(qNum < blockArray.length)
{
blockArray[qNum].color = Color.ORANGE;
//blockArray[qNum].isSorted = true;
qNum++;

}
}
}
}
Loading